/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ // Tests that the addon commands works as they should const csscoverage = require("devtools/server/actors/csscoverage"); const PAGE_1 = TEST_BASE_HTTPS + "browser_cmd_csscoverage_page1.html"; const PAGE_2 = TEST_BASE_HTTPS + "browser_cmd_csscoverage_page2.html"; const PAGE_3 = TEST_BASE_HTTPS + "browser_cmd_csscoverage_page3.html"; const SHEET_A = TEST_BASE_HTTPS + "browser_cmd_csscoverage_sheetA.css"; const SHEET_B = TEST_BASE_HTTPS + "browser_cmd_csscoverage_sheetB.css"; const SHEET_C = TEST_BASE_HTTPS + "browser_cmd_csscoverage_sheetC.css"; const SHEET_D = TEST_BASE_HTTPS + "browser_cmd_csscoverage_sheetD.css"; add_task(function*() { let options = yield helpers.openTab("about:blank"); yield helpers.openToolbar(options); let usage = yield csscoverage.getUsage(options.target); yield navigate(usage, options); yield checkPages(usage); yield checkEditorReport(usage); yield checkPageReport(usage); yield helpers.closeToolbar(options); yield helpers.closeTab(options); }); /** * Visit all the pages in the test */ function* navigate(usage, options) { yield usage.start(options.chromeWindow, options.target); ok(usage.isRunning(), "csscoverage is running"); let load1Promise = helpers.listenOnce(options.browser, "load", true); yield helpers.navigate(PAGE_1, options); // Wait for the test pages to auto-cycle yield load1Promise; is(options.window.location.href, PAGE_1, "page 1 loaded"); // Page 2 is a frame in page 1. JS in the page navigates to page 3. yield helpers.listenOnce(options.browser, "load", true); is(options.window.location.href, PAGE_3, "page 3 loaded"); yield usage.stop(); ok(!usage.isRunning(), "csscoverage not is running"); } /** * Check the expected pages have been visited */ function* checkPages(usage) { // 'load' event order. '' is for the initial location let expectedVisited = [ '', PAGE_2, PAGE_1, PAGE_3 ]; let actualVisited = yield usage._testOnly_visitedPages(); isEqualJson(actualVisited, expectedVisited, 'Visited'); } /** * Check that createEditorReport returns the expected JSON */ function* checkEditorReport(usage) { // Page1 let expectedPage1 = { reports: [ { selectorText: ".page1-test2", start: { line: 8, column: 5 }, } ] }; let actualPage1 = yield usage.createEditorReport(PAGE_1 + " \u2192