Bug 1348223 - Part 4 - Add and update tests for removing site data and cookies in the page info window. r=florian
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 22 Mar 2018 17:29:51 +0100
changeset 411975 0f1aa8fea3708404f66b24f958afc9dcd15dbfe2
parent 411974 8dec8e29532e8e5759fef70bf43d4468740c7347
child 411976 2be604b3a338474e54a6bbbc2ae58ab8445c3752
push id62240
push userjhofmann@mozilla.com
push dateThu, 05 Apr 2018 21:17:10 +0000
treeherderautoland@2be604b3a338 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1348223
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1348223 - Part 4 - Add and update tests for removing site data and cookies in the page info window. r=florian MozReview-Commit-ID: gAaComSklW
browser/base/content/test/pageinfo/browser.ini
browser/base/content/test/pageinfo/browser_pageinfo_security.js
testing/firefox-ui/tests/puppeteer/test_page_info_window.py
testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/pageinfo/deck.py
--- a/browser/base/content/test/pageinfo/browser.ini
+++ b/browser/base/content/test/pageinfo/browser.ini
@@ -8,12 +8,13 @@ support-files =
   image.html
   ../general/audio.ogg
   ../general/moz.png
   ../general/video.ogg
 [browser_pageinfo_images.js]
 [browser_pageinfo_image_info.js]
 uses-unsafe-cpows = true
 skip-if = (os == 'linux' && e10s) # bug 1161699
+[browser_pageinfo_security.js]
 [browser_pageinfo_svg_image.js]
 support-files =
   svg_image.html
   ../general/title_test.svg
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_security.js
@@ -0,0 +1,93 @@
+ChromeUtils.import("resource:///modules/SitePermissions.jsm");
+
+ChromeUtils.defineModuleGetter(this, "SiteDataTestUtils",
+                               "resource://testing-common/SiteDataTestUtils.jsm");
+ChromeUtils.defineModuleGetter(this, "DownloadUtils",
+                               "resource://gre/modules/DownloadUtils.jsm");
+
+const TEST_ORIGIN = "https://example.com";
+const TEST_SUB_ORIGIN = "https://test1.example.com";
+const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSelected.xul";
+
+// Test displaying and removing quota managed data.
+add_task(async function test_SiteData() {
+  await SiteDataTestUtils.addToIndexedDB(TEST_ORIGIN);
+
+  await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function(browser) {
+
+    let totalUsage = await SiteDataTestUtils.getQuotaUsage(TEST_ORIGIN);
+    Assert.greater(totalUsage, 0, "The total usage should not be 0");
+
+    let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
+    await BrowserTestUtils.waitForEvent(pageInfo, "load");
+
+    let label = pageInfo.document.getElementById("security-privacy-sitedata-value");
+    let clearButton = pageInfo.document.getElementById("security-clear-sitedata");
+
+    let size = DownloadUtils.convertByteUnits(totalUsage);
+
+    // The usage details are filled asynchronously, so we assert that they're present by
+    // waiting for them to be filled in.
+    // We only wait for the right unit to appear, since this number is intermittently
+    // varying by slight amounts on infra machines.
+    await BrowserTestUtils.waitForCondition(() => label.textContent.includes(size[1]),
+      "Should show site data usage in the security section.");
+    let siteDataUpdated = TestUtils.topicObserved("sitedatamanager:sites-updated");
+
+    let removeDialogPromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
+    clearButton.click();
+    await removeDialogPromise;
+
+    await siteDataUpdated;
+
+    totalUsage = await SiteDataTestUtils.getQuotaUsage(TEST_ORIGIN);
+    is(totalUsage, 0, "The total usage should be 0");
+
+    await BrowserTestUtils.waitForCondition(() => label.textContent == "No",
+      "Should show no site data usage in the security section.");
+
+    pageInfo.close();
+  });
+});
+
+// Test displaying and removing cookies.
+add_task(async function test_Cookies() {
+  // Add some test cookies.
+  SiteDataTestUtils.addToCookies(TEST_ORIGIN, "test1", "1");
+  SiteDataTestUtils.addToCookies(TEST_ORIGIN, "test2", "2");
+  SiteDataTestUtils.addToCookies(TEST_SUB_ORIGIN, "test1", "1");
+
+  await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function(browser) {
+    let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
+    await BrowserTestUtils.waitForEvent(pageInfo, "load");
+
+    let label = pageInfo.document.getElementById("security-privacy-sitedata-value");
+    let clearButton = pageInfo.document.getElementById("security-clear-sitedata");
+
+    // The usage details are filled asynchronously, so we assert that they're present by
+    // waiting for them to be filled in.
+    await BrowserTestUtils.waitForCondition(() => label.textContent.includes("cookies"),
+      "Should show cookies in the security section.");
+
+    let cookiesCleared = TestUtils.topicObserved("cookie-changed", (subj, data) => data == "deleted");
+
+    let removeDialogPromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
+    clearButton.click();
+    await removeDialogPromise;
+
+    await cookiesCleared;
+
+    let uri = Services.io.newURI(TEST_ORIGIN);
+    is(Services.cookies.countCookiesFromHost(uri.host), 0, "Cookies from the base domain should be cleared");
+
+    await BrowserTestUtils.waitForCondition(() => label.textContent == "No",
+      "Should show no cookies in the security section.");
+
+    pageInfo.close();
+  });
+});
+
+// Clean up in case we missed anything...
+add_task(async function cleanup() {
+  await SiteDataTestUtils.clear();
+});
--- a/testing/firefox-ui/tests/puppeteer/test_page_info_window.py
+++ b/testing/firefox-ui/tests/puppeteer/test_page_info_window.py
@@ -40,17 +40,16 @@ class TestPageInfoWindow(PuppeteerMixin,
 
         self.assertEqual(panel.element.get_property('localName'), 'vbox')
 
         self.assertEqual(panel.domain.get_property('localName'), 'textbox')
         self.assertEqual(panel.owner.get_property('localName'), 'textbox')
         self.assertEqual(panel.verifier.get_property('localName'), 'textbox')
 
         self.assertEqual(panel.view_certificate.get_property('localName'), 'button')
-        self.assertEqual(panel.view_cookies.get_property('localName'), 'button')
         self.assertEqual(panel.view_passwords.get_property('localName'), 'button')
 
     def test_select(self):
         """Test properties and methods for switching between panels."""
         page_info = self.browser.open_page_info_window()
         deck = page_info.deck
 
         self.assertEqual(deck.selected_panel, deck.general)
--- a/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/pageinfo/deck.py
+++ b/testing/marionette/puppeteer/firefox/firefox_puppeteer/ui/pageinfo/deck.py
@@ -185,22 +185,14 @@ class SecurityPanel(PageInfoPanel):
     def view_certificate(self):
         """The DOM element which represents the view certificate button.
 
         :returns: Reference to the button element.
         """
         return self.element.find_element(By.ID, 'security-view-cert')
 
     @property
-    def view_cookies(self):
-        """The DOM element which represents the view cookies button.
-
-        :returns: Reference to the button element.
-        """
-        return self.element.find_element(By.ID, 'security-view-cookies')
-
-    @property
     def view_passwords(self):
         """The DOM element which represents the view passwords button.
 
         :returns: Reference to the button element.
         """
         return self.element.find_element(By.ID, 'security-view-password')