Commit 414e027d authored by Solomon Kinard's avatar Solomon Kinard Committed by Commit Bot

[Extensions] Use `text` instead of repeating `search` for field name.

Though this is a breaking change, it's safe because the API was only
available on dev channel in M86.

Bug: 1108940

Change-Id: I4ee1718c8cdeda2e3fe28fcd810b894e656cc8f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398888
Commit-Queue: Solomon Kinard <solomonkinard@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806909}
parent dc5b32ae
...@@ -34,13 +34,13 @@ ExtensionFunction::ResponseAction SearchQueryFunction::Run() { ...@@ -34,13 +34,13 @@ ExtensionFunction::ResponseAction SearchQueryFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
// Convenience for input params. // Convenience for input params.
const std::string& search = params->query_info.search; const std::string& text = params->query_info.text;
const std::unique_ptr<int>& tab_id = params->query_info.tab_id; const std::unique_ptr<int>& tab_id = params->query_info.tab_id;
Disposition disposition = params->query_info.disposition; Disposition disposition = params->query_info.disposition;
// Simple validation of input params. // Simple validation of input params.
if (search.empty()) { if (text.empty()) {
return RespondNow(Error("Empty search parameter.")); return RespondNow(Error("Empty text parameter."));
} }
if (tab_id.get() && disposition != Disposition::DISPOSITION_NONE) { if (tab_id.get() && disposition != Disposition::DISPOSITION_NONE) {
return RespondNow(Error("Cannot set both 'disposition' and 'tabId'.")); return RespondNow(Error("Cannot set both 'disposition' and 'tabId'."));
...@@ -94,7 +94,7 @@ ExtensionFunction::ResponseAction SearchQueryFunction::Run() { ...@@ -94,7 +94,7 @@ ExtensionFunction::ResponseAction SearchQueryFunction::Run() {
TemplateURLServiceFactory::GetForProfile(profile); TemplateURLServiceFactory::GetForProfile(profile);
DCHECK(url_service); DCHECK(url_service);
GURL url = GURL url =
GetDefaultSearchURLForSearchTerms(url_service, base::UTF8ToUTF16(search)); GetDefaultSearchURLForSearchTerms(url_service, base::UTF8ToUTF16(text));
if (!url.is_valid()) { if (!url.is_valid()) {
return RespondNow(Error("Missing default search provider.")); return RespondNow(Error("Missing default search provider."));
} }
......
...@@ -125,26 +125,26 @@ void SearchApiUnitTest::RunFunctionAndExpectError( ...@@ -125,26 +125,26 @@ void SearchApiUnitTest::RunFunctionAndExpectError(
// Test for error if search field is empty string. // Test for error if search field is empty string.
TEST_F(SearchApiUnitTest, QueryEmpty) { TEST_F(SearchApiUnitTest, QueryEmpty) {
RunFunctionAndExpectError(R"([{"search": ""}])", "Empty search parameter."); RunFunctionAndExpectError(R"([{"text": ""}])", "Empty text parameter.");
} }
// Test for error if both disposition and tabId are populated. // Test for error if both disposition and tabId are populated.
TEST_F(SearchApiUnitTest, DispositionAndTabIDValid) { TEST_F(SearchApiUnitTest, DispositionAndTabIDValid) {
RunFunctionAndExpectError( RunFunctionAndExpectError(
R"([{"search": "1", "disposition": "NEW_TAB", "tabId": 1}])", R"([{"text": "1", "disposition": "NEW_TAB", "tabId": 1}])",
"Cannot set both 'disposition' and 'tabId'."); "Cannot set both 'disposition' and 'tabId'.");
} }
// Test for error if both disposition and tabId are populated. // Test for error if both disposition and tabId are populated.
TEST_F(SearchApiUnitTest, InvalidTabId) { TEST_F(SearchApiUnitTest, InvalidTabId) {
RunFunctionAndExpectError(R"([{"search": "1", "tabId": -1}])", RunFunctionAndExpectError(R"([{"text": "1", "tabId": -1}])",
"No tab with id: -1."); "No tab with id: -1.");
} }
// Test for error if missing browser context. // Test for error if missing browser context.
TEST_F(SearchApiUnitTest, NoActiveBrowser) { TEST_F(SearchApiUnitTest, NoActiveBrowser) {
auto result = api_test_utils::RunFunctionAndReturnError( auto result = api_test_utils::RunFunctionAndReturnError(
function(), R"([{"search": "1"}])", nullptr); function(), R"([{"text": "1"}])", nullptr);
EXPECT_EQ("No active browser.", result); EXPECT_EQ("No active browser.", result);
} }
......
...@@ -17,7 +17,7 @@ namespace search { ...@@ -17,7 +17,7 @@ namespace search {
dictionary QueryInfo { dictionary QueryInfo {
// String to query with the default search provider. // String to query with the default search provider.
DOMString search; DOMString text;
// Location where search results should be displayed. // Location where search results should be displayed.
// <code>CURRENT_TAB</code> is the default. // <code>CURRENT_TAB</code> is the default.
......
...@@ -15,14 +15,14 @@ chrome.test.runTests([ ...@@ -15,14 +15,14 @@ chrome.test.runTests([
function IncognitoSpecificTab() { function IncognitoSpecificTab() {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
const tab = tabs[0]; const tab = tabs[0];
testHelper(tabs, {search: SEARCH_WORDS, tabId: tab.id}); testHelper(tabs, {text: SEARCH_WORDS, tabId: tab.id});
}); });
}, },
// Verify search results shown in current incognito tab. // Verify search results shown in current incognito tab.
function IncognitoNoDisposition() { function IncognitoNoDisposition() {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
testHelper(tabs, {search: SEARCH_WORDS}); testHelper(tabs, {text: SEARCH_WORDS});
}); });
}, },
]); ]);
......
...@@ -18,14 +18,14 @@ if (chrome.extension.inIncognitoContext) { ...@@ -18,14 +18,14 @@ if (chrome.extension.inIncognitoContext) {
// Verify search results shown in specified incognito tab. // Verify search results shown in specified incognito tab.
function IncognitoSpecificTab() { function IncognitoSpecificTab() {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
testHelper(tabs, {search: SEARCH_WORDS, tabId: tabs[0].id}); testHelper(tabs, {text: SEARCH_WORDS, tabId: tabs[0].id});
}); });
}, },
// Verify search results shown in current incognito tab. // Verify search results shown in current incognito tab.
function IncognitoNoDisposition() { function IncognitoNoDisposition() {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
testHelper(tabs, {search: SEARCH_WORDS}); testHelper(tabs, {text: SEARCH_WORDS});
}); });
}, },
]); ]);
......
...@@ -15,8 +15,8 @@ chrome.test.runTests([ ...@@ -15,8 +15,8 @@ chrome.test.runTests([
// Error if search string is empty. // Error if search string is empty.
function QueryEmpty() { function QueryEmpty() {
chrome.search.query({search: ''}, function() { chrome.search.query({text: ''}, function() {
assertLastError('Empty search parameter.'); assertLastError('Empty text parameter.');
succeed(); succeed();
}); });
}, },
...@@ -25,7 +25,7 @@ chrome.test.runTests([ ...@@ -25,7 +25,7 @@ chrome.test.runTests([
function QueryPopulatedDispositionEmpty() { function QueryPopulatedDispositionEmpty() {
chrome.tabs.create({}, (tab) => { chrome.tabs.create({}, (tab) => {
waitForTabAndPass(tab.id); waitForTabAndPass(tab.id);
chrome.search.query({search: SEARCH_WORDS}, () => {}); chrome.search.query({text: SEARCH_WORDS}, () => {});
}); });
}, },
...@@ -33,7 +33,7 @@ chrome.test.runTests([ ...@@ -33,7 +33,7 @@ chrome.test.runTests([
function QueryPopulatedDispositionCurrentTab() { function QueryPopulatedDispositionCurrentTab() {
chrome.tabs.create({}, (tab) => { chrome.tabs.create({}, (tab) => {
waitForTabAndPass(tab.id); waitForTabAndPass(tab.id);
chrome.search.query({search: SEARCH_WORDS, disposition: 'CURRENT_TAB'}); chrome.search.query({text: SEARCH_WORDS, disposition: 'CURRENT_TAB'});
}); });
}, },
...@@ -46,7 +46,7 @@ chrome.test.runTests([ ...@@ -46,7 +46,7 @@ chrome.test.runTests([
waitForAnyTab(), waitForAnyTab(),
new Promise(resolve => { new Promise(resolve => {
chrome.search.query( chrome.search.query(
{search: SEARCH_WORDS, disposition: 'NEW_TAB'}, () => { {text: SEARCH_WORDS, disposition: 'NEW_TAB'}, () => {
chrome.tabs.query( chrome.tabs.query(
{active: true, currentWindow: true}, (tabs) => { {active: true, currentWindow: true}, (tabs) => {
assertEq(1, tabs.length); assertEq(1, tabs.length);
...@@ -72,7 +72,7 @@ chrome.test.runTests([ ...@@ -72,7 +72,7 @@ chrome.test.runTests([
waitForAnyTab(), waitForAnyTab(),
new Promise((resolve) => { new Promise((resolve) => {
chrome.search.query( chrome.search.query(
{search: SEARCH_WORDS, disposition: 'NEW_WINDOW'}, () => { {text: SEARCH_WORDS, disposition: 'NEW_WINDOW'}, () => {
chrome.windows.getAll({}, (windows) => { chrome.windows.getAll({}, (windows) => {
let window = windows.find( let window = windows.find(
window => !initialWindowIds.includes(window.id)); window => !initialWindowIds.includes(window.id));
...@@ -93,13 +93,13 @@ chrome.test.runTests([ ...@@ -93,13 +93,13 @@ chrome.test.runTests([
function QueryPopulatedTabIDValid() { function QueryPopulatedTabIDValid() {
chrome.tabs.create({}, (tab) => { chrome.tabs.create({}, (tab) => {
waitForTabAndPass(tab.id); waitForTabAndPass(tab.id);
chrome.search.query({search: SEARCH_WORDS, tabId: tab.id}); chrome.search.query({text: SEARCH_WORDS, tabId: tab.id});
}); });
}, },
// Error if tab id invalid. // Error if tab id invalid.
function QueryPopulatedTabIDInvalid() { function QueryPopulatedTabIDInvalid() {
chrome.search.query({search: SEARCH_WORDS, tabId: -1}, () => { chrome.search.query({text: SEARCH_WORDS, tabId: -1}, () => {
assertLastError('No tab with id: -1.'); assertLastError('No tab with id: -1.');
succeed(); succeed();
}); });
...@@ -109,7 +109,7 @@ chrome.test.runTests([ ...@@ -109,7 +109,7 @@ chrome.test.runTests([
function QueryAndDispositionPopulatedTabIDValid() { function QueryAndDispositionPopulatedTabIDValid() {
chrome.tabs.query({active: true}, (tabs) => { chrome.tabs.query({active: true}, (tabs) => {
chrome.search.query( chrome.search.query(
{search: SEARCH_WORDS, tabId: tabs[0].id, disposition: 'NEW_TAB'}, {text: SEARCH_WORDS, tabId: tabs[0].id, disposition: 'NEW_TAB'},
() => { () => {
assertLastError('Cannot set both \'disposition\' and \'tabId\'.'); assertLastError('Cannot set both \'disposition\' and \'tabId\'.');
succeed(); succeed();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment