[Pkg-mozext-commits] [requestpolicy] 96/257: [tst][add] Tabs tests

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:20:01 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 2775a88e09e62273b30b1626e8bee39872ec1e17
Author: Martin Kimmerle <dev at 256k.de>
Date:   Fri Oct 16 18:32:21 2015 +0200

    [tst][add] Tabs tests
    
    There haven't been any tests for the Tabs library yet.
---
 tests/content/slowly_loading_page.php            | 45 ++++++++++++++++++++++++
 tests/marionette/rp_puppeteer/tests/manifest.ini |  1 +
 tests/marionette/rp_puppeteer/tests/test_tabs.py | 38 ++++++++++++++++++++
 tests/marionette/rp_puppeteer/ui/tabs.py         |  1 +
 4 files changed, 85 insertions(+)

diff --git a/tests/content/slowly_loading_page.php b/tests/content/slowly_loading_page.php
new file mode 100755
index 0000000..14d0247
--- /dev/null
+++ b/tests/content/slowly_loading_page.php
@@ -0,0 +1,45 @@
+<?php
+
+function ms2str($n_milliseconds) {
+    return $n_milliseconds . ' ms';
+}
+
+if (isset($_GET['load_duration'])) {
+    $load_duration = (int) $_GET['load_duration'];
+} else {
+    $load_duration = 300;
+}
+
+?>
+
+<!doctype html>
+<html>
+<head>
+  <meta charset="utf-8" />
+  <title>Slowly loading page</title>
+</head>
+<body>
+
+<?php
+
+echo '
+<p style="margin: 2em">
+  This page should take at least ' . ms2str($load_duration) . '
+  to finish loading.
+</p>
+
+<ul>';
+
+$initial_time = microtime(true);
+do {
+    usleep(500); // sleep 0.5ms
+    $time_difference = (microtime(true) - $initial_time) * 1000;
+    echo '<li>Time passed: ' . ms2str($time_difference) . '</li>';
+} while ($time_difference < $load_duration);
+
+echo '</ul>';
+
+?>
+
+</body>
+</html>
diff --git a/tests/marionette/rp_puppeteer/tests/manifest.ini b/tests/marionette/rp_puppeteer/tests/manifest.ini
index 78dd419..ffd1e0f 100644
--- a/tests/marionette/rp_puppeteer/tests/manifest.ini
+++ b/tests/marionette/rp_puppeteer/tests/manifest.ini
@@ -6,5 +6,6 @@
 [test_request_log.py]
 [test_requests.py]
 [test_rules.py]
+[test_tabs.py]
 [test_web_utils.py]
 [test_your_policy.py]
diff --git a/tests/marionette/rp_puppeteer/tests/test_tabs.py b/tests/marionette/rp_puppeteer/tests/test_tabs.py
new file mode 100644
index 0000000..b3baf56
--- /dev/null
+++ b/tests/marionette/rp_puppeteer/tests/test_tabs.py
@@ -0,0 +1,38 @@
+# 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
+
+
+PRE_PATH = "http://www.maindomain.test/"
+
+
+class TestTabs(RequestPolicyTestCase):
+
+    def test_wait_until_loaded(self):
+        test_url = "slowly_loading_page.php?load_duration=300"
+        with self.marionette.using_context("content"):
+            url_with_link = PRE_PATH + "link.html?" + test_url
+            self.marionette.navigate(url_with_link)
+            link = self.marionette.find_element("tag name", "a")
+
+        # Open Link in New Tab (background).
+        self.ctx_menu.select_entry("context-openlinkintab", link)
+
+        tabbar = self.browser.tabbar
+        new_tab = tabbar.tabs[1]
+        self.assertIs(tabbar.selected_index, 0)
+
+        # The action "Open Link in New Tab" above does _not_ include a
+        # "wait for tab" action. Since the page's load should be much slower
+        # than this test, the tab should be still loading at this point.
+        self.assertFalse(self.tabs.is_loaded(new_tab))
+
+        # FUNCTION UNDER TEST:
+        self.tabs.wait_until_loaded(new_tab)
+        self.assertTrue(self.tabs.is_loaded(new_tab),
+                        "The tab should now be loaded.")
+        self.assertEqual(new_tab.location, PRE_PATH + test_url)
+
+        new_tab.close()
diff --git a/tests/marionette/rp_puppeteer/ui/tabs.py b/tests/marionette/rp_puppeteer/ui/tabs.py
index 70385b6..39c644d 100644
--- a/tests/marionette/rp_puppeteer/ui/tabs.py
+++ b/tests/marionette/rp_puppeteer/ui/tabs.py
@@ -7,6 +7,7 @@ from marionette_driver.wait import Wait
 
 
 class Tabs(BaseLib):
+
     def is_loaded(self, tab):
         return tab.tab_element.get_attribute("busy") == None
 

-- 
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