summaryrefslogtreecommitdiffstats
path: root/testing/firefox-ui/tests/functional/locationbar/test_access_locationbar.py
blob: 160a402c2075860bee62c4051a2f203a417b8cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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 import PuppeteerMixin
from marionette_driver import Wait
from marionette_harness import MarionetteTestCase


class TestAccessLocationBar(PuppeteerMixin, MarionetteTestCase):

    def setUp(self):
        super(TestAccessLocationBar, self).setUp()

        # Clear complete history so there's no interference from previous entries.
        self.puppeteer.places.remove_all_history()

        self.test_urls = [
            'layout/mozilla_projects.html',
            'layout/mozilla.html',
            'layout/mozilla_mission.html'
        ]
        self.test_urls = [self.marionette.absolute_url(t)
                          for t in self.test_urls]

        self.locationbar = self.browser.navbar.locationbar
        self.autocomplete_results = self.locationbar.autocomplete_results
        self.urlbar = self.locationbar.urlbar

    def test_access_locationbar_history(self):

        # Open some local pages, then about:blank
        def load_urls():
            with self.marionette.using_context('content'):
                for url in self.test_urls:
                    self.marionette.navigate(url)
        self.puppeteer.places.wait_for_visited(self.test_urls, load_urls)
        with self.marionette.using_context('content'):
            self.marionette.navigate('about:blank')

        # Need to blur url bar or autocomplete won't load - bug 1038614
        self.marionette.execute_script("""arguments[0].blur();""", script_args=[self.urlbar])

        # Clear contents of url bar to focus, then arrow down for list of visited sites
        # Verify that autocomplete is open and results are displayed
        self.locationbar.clear()
        self.urlbar.send_keys(self.puppeteer.keys.ARROW_DOWN)
        Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open)
        Wait(self.marionette).until(lambda _: len(self.autocomplete_results.visible_results) > 1)

        # Arrow down again to select first item in list, appearing in reversed order, as loaded.
        # Verify first item.
        self.urlbar.send_keys(self.puppeteer.keys.ARROW_DOWN)
        Wait(self.marionette).until(lambda _: self.autocomplete_results.selected_index == '0')
        self.assertIn('mission', self.locationbar.value)

        # Navigate to the currently selected url
        # Verify it loads by comparing the page url to the test url
        self.urlbar.send_keys(self.puppeteer.keys.ENTER)
        self.assertEqual(self.locationbar.value, self.test_urls[-1])