[Pkg-mozext-commits] [requestpolicy] 223/257: [fix] menu: rule counter on reload

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:20:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 7db3e4ef5b7f315724409062cb69b4fe687be842
Author: Martin Kimmerle <dev at 256k.de>
Date:   Sat Dec 19 15:14:12 2015 +0100

    [fix] menu: rule counter on reload
    
    Fix #611, Block count increase after refresh webpage.
    
    Other changes:
    * Tests added
    * new Menu library
    * tests against #611
    * Changed `img_1.html` so it shows an existing image.
    * Console observer: ignore an SVG error
---
 src/content/lib/request-processor.jsm              | 29 +++++++---
 tests/content/img_1.html                           | 16 ++++--
 .../dev-helper/content/console-observer.jsm        |  3 +-
 tests/marionette/rp_puppeteer/__init__.py          |  4 ++
 tests/marionette/rp_puppeteer/tests/manifest.ini   |  1 +
 tests/marionette/rp_puppeteer/tests/test_menu.py   | 28 ++++++++++
 .../marionette/rp_puppeteer/tests/test_requests.py |  4 +-
 tests/marionette/rp_puppeteer/ui/menu.py           | 62 ++++++++++++++++++++++
 tests/marionette/tests/manifest.ini                |  1 +
 tests/marionette/tests/menu/manifest.ini           |  1 +
 tests/marionette/tests/menu/test_num_requests.py   | 59 ++++++++++++++++++++
 11 files changed, 193 insertions(+), 15 deletions(-)

diff --git a/src/content/lib/request-processor.jsm b/src/content/lib/request-processor.jsm
index 4f221b0..a6d062e 100644
--- a/src/content/lib/request-processor.jsm
+++ b/src/content/lib/request-processor.jsm
@@ -142,6 +142,17 @@ var RequestProcessor = (function() {
     }
   }
 
+  /**
+   * Remove all saved requests from a specific origin URI. Remove both
+   * accepted and rejected requests.
+   *
+   * @param {string} uri The origin URI.
+   */
+  function removeSavedRequestsByOriginURI(uri) {
+    self._allowedRequests.removeOriginUri(uri);
+    self._rejectedRequests.removeOriginUri(uri);
+  }
+
   // We always call this from shouldLoad to reject a request.
   function reject(reason, request) {
     Logger.warning(Logger.TYPE_CONTENT, "** BLOCKED ** reason: " + reason +
@@ -214,15 +225,16 @@ var RequestProcessor = (function() {
     return CP_OK;
   }
 
+  /**
+   * @param {string} originUri
+   * @param {string} destUri
+   * @param {Boolean} isInsert
+   * @param {RequestResult} requestResult
+   */
   function recordAllowedRequest(originUri, destUri, isInsert, requestResult) {
-    // Reset the accepted and rejected requests originating from this
-    // destination. That is, if this accepts a request to a uri that may itself
-    // originate further requests, reset the information about what that page is
-    // accepting and rejecting.
-    // If "isInsert" is set, then we don't want to clear the destUri info.
-    if (true !== isInsert) {
-      self._allowedRequests.removeOriginUri(destUri);
-      self._rejectedRequests.removeOriginUri(destUri);
+    if (!isInsert) {
+      // The destination URI may itself originate further requests.
+      removeSavedRequestsByOriginURI(destUri);
     }
     self._rejectedRequests.removeRequest(originUri, destUri);
     self._allowedRequests.addRequest(originUri, destUri, requestResult);
@@ -519,6 +531,7 @@ var RequestProcessor = (function() {
               Logger.TYPE_CONTENT,
               "Allowing request that appears to be a URL entered in the " +
               "location bar or some other good explanation: " + destURI);
+          removeSavedRequestsByOriginURI(destURI);
           return CP_OK;
         }
       }
diff --git a/tests/content/img_1.html b/tests/content/img_1.html
index f8fe35f..cfa9ee9 100644
--- a/tests/content/img_1.html
+++ b/tests/content/img_1.html
@@ -5,13 +5,21 @@
 </head>
 <body>
 
-<p><img src="http://www.otherdomain.test/cross-site-image.png"/>
+<p>
+  cross-site image: <img src="http://www.otherdomain.test/subdirectory/flag-gray.png" />
+</p>
 
-<p><img src="same-site-image.png"/>
+<p>
+  same-site image: <img src="subdirectory/flag-gray.png" />
+</p>
 
-<p><a href="http://www.otherdomain.test/destination.html">cross-site link</a>
+<p>
+  <a href="http://www.otherdomain.test/destination.html">cross-site link</a>
+</p>
 
-<p><a href="destination.html">same-site link</a>
+<p>
+  <a href="destination.html">same-site link</a>
+</p>
 
 </body>
 </html>
diff --git a/tests/helper-addons/dev-helper/content/console-observer.jsm b/tests/helper-addons/dev-helper/content/console-observer.jsm
index 48c8af7..92387b1 100644
--- a/tests/helper-addons/dev-helper/content/console-observer.jsm
+++ b/tests/helper-addons/dev-helper/content/console-observer.jsm
@@ -48,7 +48,8 @@ function isRPException(aMessage) {
 
 const knownBugs = [
   // issue #597
-  `[JavaScript Error: "TypeError: sub is undefined" {file: "chrome://rpcontinued/content/lib/subscription.jsm"`
+  `[JavaScript Error: "TypeError: sub is undefined" {file: "chrome://rpcontinued/content/lib/subscription.jsm"`,
+  `[JavaScript Warning: "Expected end of value but found '10'.  Error in parsing value for 'font-family'.  Declaration dropped." {file: "chrome://rpcontinued/skin/`,
 ];
 
 function isKnownBug(aMessage) {
diff --git a/tests/marionette/rp_puppeteer/__init__.py b/tests/marionette/rp_puppeteer/__init__.py
index 31664c5..8726bd6 100644
--- a/tests/marionette/rp_puppeteer/__init__.py
+++ b/tests/marionette/rp_puppeteer/__init__.py
@@ -44,6 +44,10 @@ class RequestPolicyPuppeteer(object):
     def ctx_menu(self):
         pass
 
+    @use_class_as_property('ui.menu.Menu')
+    def menu(self):
+        pass
+
     @use_class_as_property('ui.redirect_notification.RedirectNotification')
     def redir(self):
         pass
diff --git a/tests/marionette/rp_puppeteer/tests/manifest.ini b/tests/marionette/rp_puppeteer/tests/manifest.ini
index a441b7a..2831a72 100644
--- a/tests/marionette/rp_puppeteer/tests/manifest.ini
+++ b/tests/marionette/rp_puppeteer/tests/manifest.ini
@@ -2,6 +2,7 @@
 [test_context_menu.py]
 [test_error_detection.py]
 [test_l10n.py]
+[test_menu.py]
 [test_prefs.py]
 [test_request_log.py]
 [test_requests.py]
diff --git a/tests/marionette/rp_puppeteer/tests/test_menu.py b/tests/marionette/rp_puppeteer/tests/test_menu.py
new file mode 100644
index 0000000..78dd100
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/tests/test_menu.py
@@ -0,0 +1,28 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from rp_ui_harness import RequestPolicyTestCase
+
+
+class TestMenu(RequestPolicyTestCase):
+
+    def tearDown(self):
+        try:
+            self.menu.close()
+        finally:
+            super(RequestPolicyTestCase, self).tearDown()
+
+    def test_open_close(self):
+        self.assertFalse(self.menu.is_open())
+        self.menu.open()
+        self.assertTrue(self.menu.is_open())
+        self.menu.close()
+        self.assertFalse(self.menu.is_open())
+
+    def test_total_num_requests(self):
+        with self.marionette.using_context("content"):
+            self.marionette.navigate("http://www.maindomain.test/img_1.html" +
+                                     "?TestMenu.test_total_num_requests")
+        self.menu.open()
+        self.assertEqual(4, self.menu.total_num_requests)
diff --git a/tests/marionette/rp_puppeteer/tests/test_requests.py b/tests/marionette/rp_puppeteer/tests/test_requests.py
index 4f44cd4..913eb54 100644
--- a/tests/marionette/rp_puppeteer/tests/test_requests.py
+++ b/tests/marionette/rp_puppeteer/tests/test_requests.py
@@ -174,11 +174,11 @@ class TestGettingRequests(RequestPolicyTestCase):
             },
             {
                 "origin": "http://www.maindomain.test/img_1.html",
-                "dest": "http://www.maindomain.test/same-site-image.png",
+                "dest": "http://www.maindomain.test/subdirectory/flag-gray.png",
                 "isAllowed": True
             }, {
                 "origin": "http://www.maindomain.test/img_1.html",
-                "dest": "http://www.otherdomain.test/cross-site-image.png",
+                "dest": "http://www.otherdomain.test/subdirectory/flag-gray.png",
                 "isAllowed": False
             }
         ]
diff --git a/tests/marionette/rp_puppeteer/ui/menu.py b/tests/marionette/rp_puppeteer/ui/menu.py
new file mode 100644
index 0000000..f243513
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/ui/menu.py
@@ -0,0 +1,62 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from firefox_puppeteer.base import BaseLib
+from marionette_driver.wait import Wait
+import re
+
+
+class Menu(BaseLib):
+
+    #################################
+    # Public Properties and Methods #
+    #################################
+
+    @property
+    def total_num_requests(self):
+        label_element = self._popup.find_element("id", "rpc-origin-num-requests")
+        text = label_element.get_attribute("value")
+        match = re.match(r"^(\d+) \((\d+)\+(\d+)\)$", text)
+        return int(match.group(1))
+
+    def open(self):
+        self._ensure_popup_state("open")
+
+    def is_open(self):
+        return self._popup_state == "open"
+
+    def close(self):
+        self._ensure_popup_state("closed")
+
+    ##################################
+    # Private Properties and Methods #
+    ##################################
+
+    @property
+    def _toolbar_button(self):
+        return self.marionette.find_element("id", "rpcontinuedToolbarButton")
+
+    @property
+    def _popup(self):
+        return self.marionette.find_element("id", "rpc-popup")
+
+    @property
+    def _popup_state(self):
+        return self._popup.get_attribute("state")
+
+    def _ensure_popup_state(self, state):
+        assert state in ["open", "closed"]
+
+        if self._popup_state == state:
+            return
+
+        fn_name = "openPopup" if state == "open" else "hidePopup"
+
+        self.marionette.execute_script("""
+          let popup = arguments[0];
+          let fnName = arguments[1];
+          popup[fnName]();
+        """, script_args=[self._popup, fn_name])
+
+        Wait(self.marionette).until(lambda _: self._popup_state == state)
diff --git a/tests/marionette/tests/manifest.ini b/tests/marionette/tests/manifest.ini
index a6ea341..f8245ef 100644
--- a/tests/marionette/tests/manifest.ini
+++ b/tests/marionette/tests/manifest.ini
@@ -1,5 +1,6 @@
 [include:addon_install_and_upgrade/manifest.ini]
 [include:links/manifest.ini]
+[include:menu/manifest.ini]
 [include:policy/manifest.ini]
 [include:redirections/manifest.ini]
 [include:settings/manifest.ini]
diff --git a/tests/marionette/tests/menu/manifest.ini b/tests/marionette/tests/menu/manifest.ini
new file mode 100644
index 0000000..6957697
--- /dev/null
+++ b/tests/marionette/tests/menu/manifest.ini
@@ -0,0 +1 @@
+[test_num_requests.py]
diff --git a/tests/marionette/tests/menu/test_num_requests.py b/tests/marionette/tests/menu/test_num_requests.py
new file mode 100644
index 0000000..8344f39
--- /dev/null
+++ b/tests/marionette/tests/menu/test_num_requests.py
@@ -0,0 +1,59 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from rp_ui_harness import RequestPolicyTestCase
+
+
+class TestTotalNumRequestsAfterReload(RequestPolicyTestCase):
+
+    TEST_URL = "http://www.maindomain.test/img_1.html";
+
+    def setUp(self):
+        super(TestTotalNumRequestsAfterReload, self).setUp()
+        self.locationbar = self.browser.navbar.locationbar
+
+    ################
+    # Test Methods #
+    ################
+
+    def test_using_navigate(self):
+        self._test(lambda url: self._navigate(url))
+
+    def test_using_locationbar(self):
+        self._test(lambda url: self.locationbar.load_url(url))
+
+    def test_using_reload_button(self):
+        self._test(lambda _: self.locationbar.reload_url(trigger="button"))
+
+    def test_using_reload_shortcut(self):
+        # CTRL + R
+        self._test(lambda _: self.locationbar.reload_url(trigger="shortcut"))
+
+    def test_using_reload_shortcut2(self):
+        # F5
+        self._test(lambda _: self.locationbar.reload_url(trigger="shortcut2"))
+
+    ##########################
+    # Private Helper Methods #
+    ##########################
+
+    def _test(self, reload_url):
+        self._navigate(self.TEST_URL)
+        n_before = self._get_num_requests()
+        reload_url(self.TEST_URL)
+        n_after = self._get_num_requests()
+        # Sometimes (probably on every first page load) `shouldLoad` is
+        # called twice for each request, so assert "GreaterEqual" instead
+        # of just "Equal".
+        self.assertGreaterEqual(n_before, n_after)
+
+    def _get_num_requests(self):
+        self.menu.open()
+        num_requests = self.menu.total_num_requests
+        self.menu.close()
+        return num_requests
+
+    def _navigate(self, url):
+        with self.marionette.using_context("content"):
+            self.marionette.navigate(url)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list