Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / search_engines_private / test.js
blob1d03ecc18cd300a57976c1fce5db415104d4c8aa
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This just tests the interface. It does not test for specific results, only
6 // that callbacks are correctly invoked, expected parameters are correct,
7 // and failures are detected.
9 function callbackResult(result) {
10 if (chrome.runtime.lastError)
11 chrome.test.fail(chrome.runtime.lastError.message);
12 else if (result == false)
13 chrome.test.fail('Failed: ' + result);
16 var availableTests = [
17 function setSelectedSearchEngine() {
18 chrome.searchEnginesPrivate.addOtherSearchEngine(
19 'name1', 'search1.com', 'http://search1.com');
20 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
21 for (var i = 0; i < engines.length; i++) {
22 if (engines[i].name == 'name1') {
23 chrome.test.assertTrue(!engines[i].isSelected);
24 chrome.searchEnginesPrivate.setSelectedSearchEngine(engines[i].guid);
28 chrome.searchEnginesPrivate.getSearchEngines(function(newEngines) {
29 for (var i = 0; i < newEngines.length; i++) {
30 if (newEngines[i].name == 'name1') {
31 chrome.test.assertTrue(newEngines[i].isSelected);
32 chrome.test.succeed();
33 return;
36 chrome.test.fail();
37 });
38 });
41 function onSearchEnginesChanged() {
42 chrome.searchEnginesPrivate.addOtherSearchEngine(
43 'name1', 'search1.com', 'http://search1.com/%s');
44 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener(
45 function(engines) {
46 for (var i = 0; i < engines.length; i++) {
47 if (engines[i].name == 'name1') {
48 chrome.test.assertTrue(engines[engines.length - 1].isSelected);
49 chrome.test.succeed();
50 return;
53 chrome.test.fail();
54 });
56 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
57 // Setting an 'other' search engine as default should cause the
58 // onSearchEnginesChanged event to fire.
59 chrome.searchEnginesPrivate.setSelectedSearchEngine(
60 engines[engines.length - 1].guid);
61 });
64 function addNewSearchEngine() {
65 var testName = 'name';
66 var testKeyword = 'search.com';
67 var testUrl = 'http://search.com';
68 chrome.searchEnginesPrivate.addOtherSearchEngine(
69 testName, testKeyword, testUrl);
70 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
71 for (var i = 0; i < engines.length; i++) {
72 if (engines[i].name == testName) {
73 chrome.test.assertEq(testKeyword, engines[i].keyword);
74 chrome.test.assertEq(testUrl, engines[i].url);
75 chrome.test.succeed();
76 return;
79 chrome.test.fail();
80 });
83 function updateSearchEngine() {
84 chrome.searchEnginesPrivate.addOtherSearchEngine(
85 'name1', 'search1.com', 'http://search1.com');
86 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
87 chrome.searchEnginesPrivate.updateSearchEngine(
88 engines[0].guid, 'name2', 'search2.com', 'http://search2.com');
89 chrome.searchEnginesPrivate.getSearchEngines(function(newEngines) {
90 chrome.test.assertEq('name2', newEngines[0].name);
91 chrome.test.assertEq('search2.com', newEngines[0].keyword);
92 chrome.test.assertEq('http://search2.com', newEngines[0].url);
93 chrome.test.succeed();
94 });
95 });
98 function removeSearchEngine() {
99 chrome.searchEnginesPrivate.addOtherSearchEngine(
100 'name1', 'search1.com', 'http://search1.com');
101 chrome.searchEnginesPrivate.addOtherSearchEngine(
102 'name2', 'search2.com', 'http://search2.com');
103 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
104 var engine1Guid = engines[1].guid;
105 chrome.searchEnginesPrivate.removeSearchEngine(engine1Guid);
107 chrome.searchEnginesPrivate.getSearchEngines(function(newEngines) {
108 for (var i = 0; i < newEngines.length; i++) {
109 chrome.test.assertFalse(newEngines[i].guid == engine1Guid);
111 chrome.test.succeed();
117 var testToRun = window.location.search.substring(1);
118 chrome.test.runTests(availableTests.filter(function(op) {
119 return op.name == testToRun;
120 }));