Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/test/data/extensions/api_test/search_engines_private/test.js

Issue 1109563003: Implement remaining chrome.searchEnginesPrivate methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address last comment sync fix trybot failure Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This just tests the interface. It does not test for specific results, only 5 // This just tests the interface. It does not test for specific results, only
6 // that callbacks are correctly invoked, expected parameters are correct, 6 // that callbacks are correctly invoked, expected parameters are correct,
7 // and failures are detected. 7 // and failures are detected.
8 8
9 function callbackResult(result) { 9 function callbackResult(result) {
10 if (chrome.runtime.lastError) 10 if (chrome.runtime.lastError)
11 chrome.test.fail(chrome.runtime.lastError.message); 11 chrome.test.fail(chrome.runtime.lastError.message);
12 else if (result == false) 12 else if (result == false)
13 chrome.test.fail('Failed: ' + result); 13 chrome.test.fail('Failed: ' + result);
14 } 14 }
15 15
16 var availableTests = [ 16 var availableTests = [
17 function setSelectedSearchEngine() { 17 function setSelectedSearchEngine() {
18 chrome.searchEnginesPrivate.getDefaultSearchEngines(function(engines) { 18 chrome.searchEnginesPrivate.addOtherSearchEngine(
19 'name1', 'search1.com', 'http://search1.com');
20 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
19 chrome.searchEnginesPrivate.setSelectedSearchEngine( 21 chrome.searchEnginesPrivate.setSelectedSearchEngine(
20 engines[engines.length - 1].guid); 22 engines[engines.length - 1].guid);
21 chrome.searchEnginesPrivate.getDefaultSearchEngines(function(newEngines) { 23 chrome.searchEnginesPrivate.getSearchEngines(function(newEngines) {
22 chrome.test.assertTrue(newEngines[newEngines.length - 1].isSelected); 24 chrome.test.assertTrue(newEngines[newEngines.length - 1].isSelected);
23 chrome.test.succeed(); 25 chrome.test.succeed();
24 }); 26 });
25 }); 27 });
26 }, 28 },
27 29
28 function onDefaultSearchEnginesChanged() { 30 function onSearchEnginesChanged() {
29 chrome.searchEnginesPrivate.onDefaultSearchEnginesChanged.addListener( 31 chrome.searchEnginesPrivate.addOtherSearchEngine(
32 'name1', 'search1.com', 'http://search1.com/%s');
33 chrome.searchEnginesPrivate.onSearchEnginesChanged.addListener(
30 function(engines) { 34 function(engines) {
31 chrome.test.assertTrue(engines[1].isSelected, 35 for (var i = 0; i < engines.length; i++) {
32 'Engine 1 should be selected'); 36 if (engines[i].name == 'name1') {
37 chrome.test.assertTrue(engines[engines.length - 1].isSelected);
38 chrome.test.succeed();
39 return;
40 }
41 }
42 chrome.test.fail();
43 });
44
45 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
46 // Setting an 'other' search engine as default should cause the
47 // onSearchEnginesChanged event to fire.
48 chrome.searchEnginesPrivate.setSelectedSearchEngine(
49 engines[engines.length - 1].guid);
50 });
51 },
52
53 function addNewSearchEngine() {
54 var testName = 'name';
55 var testKeyword = 'search.com';
56 var testUrl = 'http://search.com';
57 chrome.searchEnginesPrivate.addOtherSearchEngine(
58 testName, testKeyword, testUrl);
59 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
60 for (var i = 0; i < engines.length; i++) {
61 if (engines[i].name == testName) {
62 chrome.test.assertEq(testKeyword, engines[i].keyword);
63 chrome.test.assertEq(testUrl, engines[i].url);
33 chrome.test.succeed(); 64 chrome.test.succeed();
34 }); 65 return;
35 chrome.searchEnginesPrivate.getDefaultSearchEngines(function(engines) { 66 }
36 chrome.searchEnginesPrivate.setSelectedSearchEngine(engines[1].guid); 67 }
68 chrome.test.fail();
37 }); 69 });
38 } 70 },
71
72 function updateSearchEngine() {
73 chrome.searchEnginesPrivate.addOtherSearchEngine(
74 'name1', 'search1.com', 'http://search1.com');
75 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
76 chrome.searchEnginesPrivate.updateSearchEngine(
77 engines[0].guid, 'name2', 'search2.com', 'http://search2.com');
78 chrome.searchEnginesPrivate.getSearchEngines(function(newEngines) {
79 chrome.test.assertEq('name2', newEngines[0].name);
80 chrome.test.assertEq('search2.com', newEngines[0].keyword);
81 chrome.test.assertEq('http://search2.com', newEngines[0].url);
82 chrome.test.succeed();
83 });
84 });
85 },
86
87 function removeSearchEngine() {
88 chrome.searchEnginesPrivate.addOtherSearchEngine(
89 'name1', 'search1.com', 'http://search1.com');
90 chrome.searchEnginesPrivate.addOtherSearchEngine(
91 'name2', 'search2.com', 'http://search2.com');
92 chrome.searchEnginesPrivate.getSearchEngines(function(engines) {
93 var engine1Guid = engines[1].guid;
94 chrome.searchEnginesPrivate.removeSearchEngine(engine1Guid);
95
96 chrome.searchEnginesPrivate.getSearchEngines(function(newEngines) {
97 for (var i = 0; i < newEngines.length; i++) {
98 chrome.test.assertFalse(newEngines[i].guid == engine1Guid);
99 }
100 chrome.test.succeed();
101 });
102 });
103 },
39 ]; 104 ];
40 105
41 var testToRun = window.location.search.substring(1); 106 var testToRun = window.location.search.substring(1);
42 chrome.test.runTests(availableTests.filter(function(op) { 107 chrome.test.runTests(availableTests.filter(function(op) {
43 return op.name == testToRun; 108 return op.name == testToRun;
44 })); 109 }));
45 110
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/search_engines_private.idl ('k') | extensions/browser/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698