summaryrefslogtreecommitdiffstats
path: root/browser/components/search/test/marionette/test_engines_on_restart.py
blob: d7a0634e75892a424fca574569573e7b18e58c98 (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
# -*- coding: utf-8 -*-
# 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/.

import textwrap

from marionette_harness.marionette_test import MarionetteTestCase


class TestEnginesOnRestart(MarionetteTestCase):
    def setUp(self):
        super(TestEnginesOnRestart, self).setUp()
        self.marionette.enforce_gecko_prefs(
            {
                "browser.search.log": True,
            }
        )

    def get_default_search_engine(self):
        """Retrieve the identifier of the default search engine."""

        script = """\
        let [resolve] = arguments;
        let searchService = Components.classes[
                "@mozilla.org/browser/search-service;1"]
            .getService(Components.interfaces.nsISearchService);
        return searchService.init().then(function () {
          resolve(searchService.defaultEngine.identifier);
        });
        """

        with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
            return self.marionette.execute_async_script(textwrap.dedent(script))

    def test_engines(self):
        self.assertTrue(self.get_default_search_engine().startswith("google"))
        self.marionette.set_pref("intl.locale.requested", "kk_KZ")
        self.marionette.restart(clean=False, in_app=True)
        self.assertTrue(self.get_default_search_engine().startswith("google"))