summaryrefslogtreecommitdiffstats
path: root/testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py
blob: 9abc2d6cb9d69f92a43b5a95dbe87ff492795947 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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 By, Wait
from marionette_harness import MarionetteTestCase


class TestStarInAutocomplete(PuppeteerMixin, MarionetteTestCase):
    """ This replaces
    http://hg.mozilla.org/qa/mozmill-tests/file/default/firefox/tests/functional/testAwesomeBar/testSuggestBookmarks.js
    Check a star appears in autocomplete list for a bookmarked page.
    """

    PREF_SUGGEST_SEARCHES = 'browser.urlbar.suggest.searches'

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

        self.bookmark_panel = None
        self.test_urls = [self.marionette.absolute_url('layout/mozilla_grants.html')]

        # Disable search suggestions to only get results for history and bookmarks
        self.marionette.set_pref(self.PREF_SUGGEST_SEARCHES, False)

        with self.marionette.using_context('content'):
            self.marionette.navigate('about:blank')

        self.puppeteer.places.remove_all_history()

    def tearDown(self):
        # Close the autocomplete results
        try:
            if self.bookmark_panel:
                self.marionette.execute_script("""
                  arguments[0].hidePopup();
                """, script_args=[self.bookmark_panel])

            self.browser.navbar.locationbar.autocomplete_results.close()
            self.puppeteer.places.restore_default_bookmarks()
            self.marionette.clear_pref(self.PREF_SUGGEST_SEARCHES)
        finally:
            super(TestStarInAutocomplete, self).tearDown()

    def test_star_in_autocomplete(self):
        search_string = 'grants'

        def visit_urls():
            with self.marionette.using_context('content'):
                for url in self.test_urls:
                    self.marionette.navigate(url)

        # Navigate to all the urls specified in self.test_urls and wait for them to
        # be registered as visited
        self.puppeteer.places.wait_for_visited(self.test_urls, visit_urls)

        # Bookmark the current page using the bookmark menu
        self.browser.menubar.select_by_id('bookmarksMenu',
                                          'menu_bookmarkThisPage')

        # TODO: Replace hard-coded selector with library method when one is available
        self.bookmark_panel = self.marionette.find_element(By.ID, 'editBookmarkPanel')
        done_button = self.marionette.find_element(By.ID, 'editBookmarkPanelDoneButton')

        Wait(self.marionette).until(
            lambda mn: self.bookmark_panel.get_attribute('panelopen') == 'true')
        done_button.click()

        # We must open the blank page so the autocomplete result isn't "Switch to tab"
        with self.marionette.using_context('content'):
            self.marionette.navigate('about:blank')

        self.puppeteer.places.remove_all_history()

        # Focus the locationbar, delete any contents there, and type the search string
        locationbar = self.browser.navbar.locationbar
        locationbar.clear()
        locationbar.urlbar.send_keys(search_string)
        autocomplete_results = locationbar.autocomplete_results

        # Wait for the search string to be present, for the autocomplete results to appear
        # and for there to be exactly one autocomplete result
        Wait(self.marionette).until(lambda mn: locationbar.value == search_string)
        Wait(self.marionette).until(lambda mn: autocomplete_results.is_complete)
        Wait(self.marionette).until(lambda mn: len(autocomplete_results.visible_results) == 2)

        # Compare the highlighted text in the autocomplete result to the search string
        first_result = autocomplete_results.visible_results[1]
        matching_titles = autocomplete_results.get_matching_text(first_result, 'title')
        for title in matching_titles:
            Wait(self.marionette).until(lambda mn: title.lower() == search_string)

        self.assertIn('bookmark',
                      first_result.get_attribute('type'),
                      'The auto-complete result is a bookmark')