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() {
EXTENSION_FUNCTION_VALIDATE(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;
Disposition disposition = params->query_info.disposition;
// Simple validation of input params.
if (search.empty()) {
return RespondNow(Error("Empty search parameter."));
if (text.empty()) {
return RespondNow(Error("Empty text parameter."));
}
if (tab_id.get() && disposition != Disposition::DISPOSITION_NONE) {
return RespondNow(Error("Cannot set both 'disposition' and 'tabId'."));
......@@ -94,7 +94,7 @@ ExtensionFunction::ResponseAction SearchQueryFunction::Run() {
TemplateURLServiceFactory::GetForProfile(profile);
DCHECK(url_service);
GURL url =
GetDefaultSearchURLForSearchTerms(url_service, base::UTF8ToUTF16(search));
GetDefaultSearchURLForSearchTerms(url_service, base::UTF8ToUTF16(text));
if (!url.is_valid()) {
return RespondNow(Error("Missing default search provider."));
}
......
......@@ -125,26 +125,26 @@ void SearchApiUnitTest::RunFunctionAndExpectError(
// Test for error if search field is empty string.
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_F(SearchApiUnitTest, DispositionAndTabIDValid) {
RunFunctionAndExpectError(
R"([{"search": "1", "disposition": "NEW_TAB", "tabId": 1}])",
R"([{"text": "1", "disposition": "NEW_TAB", "tabId": 1}])",
"Cannot set both 'disposition' and 'tabId'.");
}
// Test for error if both disposition and tabId are populated.
TEST_F(SearchApiUnitTest, InvalidTabId) {
RunFunctionAndExpectError(R"([{"search": "1", "tabId": -1}])",
RunFunctionAndExpectError(R"([{"text": "1", "tabId": -1}])",
"No tab with id: -1.");
}
// Test for error if missing browser context.
TEST_F(SearchApiUnitTest, NoActiveBrowser) {
auto result = api_test_utils::RunFunctionAndReturnError(
function(), R"([{"search": "1"}])", nullptr);
function(), R"([{"text": "1"}])", nullptr);
EXPECT_EQ("No active browser.", result);
}
......
......@@ -17,7 +17,7 @@ namespace search {
dictionary QueryInfo {
// String to query with the default search provider.
DOMString search;
DOMString text;
// Location where search results should be displayed.
// <code>CURRENT_TAB</code> is the default.
......
......@@ -15,14 +15,14 @@ chrome.test.runTests([
function IncognitoSpecificTab() {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
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.
function IncognitoNoDisposition() {
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) {
// Verify search results shown in specified incognito tab.
function IncognitoSpecificTab() {
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.
function IncognitoNoDisposition() {
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([
// Error if search string is empty.
function QueryEmpty() {
chrome.search.query({search: ''}, function() {
assertLastError('Empty search parameter.');
chrome.search.query({text: ''}, function() {
assertLastError('Empty text parameter.');
succeed();
});
},
......@@ -25,7 +25,7 @@ chrome.test.runTests([
function QueryPopulatedDispositionEmpty() {
chrome.tabs.create({}, (tab) => {
waitForTabAndPass(tab.id);
chrome.search.query({search: SEARCH_WORDS}, () => {});
chrome.search.query({text: SEARCH_WORDS}, () => {});
});
},
......@@ -33,7 +33,7 @@ chrome.test.runTests([
function QueryPopulatedDispositionCurrentTab() {
chrome.tabs.create({}, (tab) => {
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([
waitForAnyTab(),
new Promise(resolve => {
chrome.search.query(
{search: SEARCH_WORDS, disposition: 'NEW_TAB'}, () => {
{text: SEARCH_WORDS, disposition: 'NEW_TAB'}, () => {
chrome.tabs.query(
{active: true, currentWindow: true}, (tabs) => {
assertEq(1, tabs.length);
......@@ -72,7 +72,7 @@ chrome.test.runTests([
waitForAnyTab(),
new Promise((resolve) => {
chrome.search.query(
{search: SEARCH_WORDS, disposition: 'NEW_WINDOW'}, () => {
{text: SEARCH_WORDS, disposition: 'NEW_WINDOW'}, () => {
chrome.windows.getAll({}, (windows) => {
let window = windows.find(
window => !initialWindowIds.includes(window.id));
......@@ -93,13 +93,13 @@ chrome.test.runTests([
function QueryPopulatedTabIDValid() {
chrome.tabs.create({}, (tab) => {
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.
function QueryPopulatedTabIDInvalid() {
chrome.search.query({search: SEARCH_WORDS, tabId: -1}, () => {
chrome.search.query({text: SEARCH_WORDS, tabId: -1}, () => {
assertLastError('No tab with id: -1.');
succeed();
});
......@@ -109,7 +109,7 @@ chrome.test.runTests([
function QueryAndDispositionPopulatedTabIDValid() {
chrome.tabs.query({active: true}, (tabs) => {
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\'.');
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