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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 5
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 function = new WindowsGetFunction(); 76 function = new WindowsGetFunction();
77 function->set_extension(extension.get()); 77 function->set_extension(extension.get());
78 result.reset(utils::ToDictionary( 78 result.reset(utils::ToDictionary(
79 utils::RunFunctionAndReturnSingleResult( 79 utils::RunFunctionAndReturnSingleResult(
80 function.get(), 80 function.get(),
81 base::StringPrintf("[%u, {\"populate\": true}]", window_id), 81 base::StringPrintf("[%u, {\"populate\": true}]", window_id),
82 browser()))); 82 browser())));
83 83
84 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id")); 84 EXPECT_EQ(window_id, utils::GetInteger(result.get(), "id"));
85 // "populate" was enabled so tabs should be populated. 85 // "populate" was enabled so tabs should be populated.
86 ListValue* tabs = NULL; 86 base::ListValue* tabs = NULL;
87 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs)); 87 EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
88 88
89 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a 89 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a
90 // browser test doesn't seem to do anything, so can't test the opposite 90 // browser test doesn't seem to do anything, so can't test the opposite
91 // either. 91 // either.
92 EXPECT_EQ(browser()->window()->IsActive(), 92 EXPECT_EQ(browser()->window()->IsActive(),
93 utils::GetBoolean(result.get(), "focused")); 93 utils::GetBoolean(result.get(), "focused"));
94 94
95 // TODO(aa): Minimized and maximized dimensions. Is there a way to set 95 // TODO(aa): Minimized and maximized dimensions. Is there a way to set
96 // minimize/maximize programmatically? 96 // minimize/maximize programmatically?
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); 146 scoped_refptr<Extension> extension(utils::CreateEmptyExtension());
147 function->set_extension(extension.get()); 147 function->set_extension(extension.get());
148 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 148 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(
149 utils::RunFunctionAndReturnSingleResult(function.get(), 149 utils::RunFunctionAndReturnSingleResult(function.get(),
150 "[]", 150 "[]",
151 new_browser))); 151 new_browser)));
152 152
153 // The id should match the window id of the browser instance that was passed 153 // The id should match the window id of the browser instance that was passed
154 // to RunFunctionAndReturnSingleResult. 154 // to RunFunctionAndReturnSingleResult.
155 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id")); 155 EXPECT_EQ(new_id, utils::GetInteger(result.get(), "id"));
156 ListValue* tabs = NULL; 156 base::ListValue* tabs = NULL;
157 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); 157 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
158 158
159 // Get the current window using the old window and make the tabs populated. 159 // Get the current window using the old window and make the tabs populated.
160 function = new WindowsGetCurrentFunction(); 160 function = new WindowsGetCurrentFunction();
161 function->set_extension(extension.get()); 161 function->set_extension(extension.get());
162 result.reset(utils::ToDictionary( 162 result.reset(utils::ToDictionary(
163 utils::RunFunctionAndReturnSingleResult(function.get(), 163 utils::RunFunctionAndReturnSingleResult(function.get(),
164 "[{\"populate\": true}]", 164 "[{\"populate\": true}]",
165 browser()))); 165 browser())));
166 166
(...skipping 16 matching lines...) Expand all
183 } 183 }
184 184
185 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); 185 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction();
186 scoped_refptr<Extension> extension(utils::CreateEmptyExtension()); 186 scoped_refptr<Extension> extension(utils::CreateEmptyExtension());
187 function->set_extension(extension.get()); 187 function->set_extension(extension.get());
188 scoped_ptr<base::ListValue> result(utils::ToList( 188 scoped_ptr<base::ListValue> result(utils::ToList(
189 utils::RunFunctionAndReturnSingleResult(function.get(), 189 utils::RunFunctionAndReturnSingleResult(function.get(),
190 "[]", 190 "[]",
191 browser()))); 191 browser())));
192 192
193 ListValue* windows = result.get(); 193 base::ListValue* windows = result.get();
194 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); 194 EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
195 for (size_t i = 0; i < NUM_WINDOWS; ++i) { 195 for (size_t i = 0; i < NUM_WINDOWS; ++i) {
196 DictionaryValue* result_window = NULL; 196 base::DictionaryValue* result_window = NULL;
197 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 197 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
198 result_ids.insert(utils::GetInteger(result_window, "id")); 198 result_ids.insert(utils::GetInteger(result_window, "id"));
199 199
200 // "populate" was not passed in so tabs are not populated. 200 // "populate" was not passed in so tabs are not populated.
201 ListValue* tabs = NULL; 201 base::ListValue* tabs = NULL;
202 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs)); 202 EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs));
203 } 203 }
204 // The returned ids should contain all the current browser instance ids. 204 // The returned ids should contain all the current browser instance ids.
205 EXPECT_EQ(window_ids, result_ids); 205 EXPECT_EQ(window_ids, result_ids);
206 206
207 result_ids.clear(); 207 result_ids.clear();
208 function = new WindowsGetAllFunction(); 208 function = new WindowsGetAllFunction();
209 function->set_extension(extension.get()); 209 function->set_extension(extension.get());
210 result.reset(utils::ToList( 210 result.reset(utils::ToList(
211 utils::RunFunctionAndReturnSingleResult(function.get(), 211 utils::RunFunctionAndReturnSingleResult(function.get(),
212 "[{\"populate\": true}]", 212 "[{\"populate\": true}]",
213 browser()))); 213 browser())));
214 214
215 windows = result.get(); 215 windows = result.get();
216 EXPECT_EQ(NUM_WINDOWS, windows->GetSize()); 216 EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
217 for (size_t i = 0; i < windows->GetSize(); ++i) { 217 for (size_t i = 0; i < windows->GetSize(); ++i) {
218 DictionaryValue* result_window = NULL; 218 base::DictionaryValue* result_window = NULL;
219 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 219 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
220 result_ids.insert(utils::GetInteger(result_window, "id")); 220 result_ids.insert(utils::GetInteger(result_window, "id"));
221 221
222 // "populate" was enabled so tabs should be populated. 222 // "populate" was enabled so tabs should be populated.
223 ListValue* tabs = NULL; 223 base::ListValue* tabs = NULL;
224 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs)); 224 EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs));
225 } 225 }
226 // The returned ids should contain all the current browser instance ids. 226 // The returned ids should contain all the current browser instance ids.
227 EXPECT_EQ(window_ids, result_ids); 227 EXPECT_EQ(window_ids, result_ids);
228 } 228 }
229 229
230 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { 230 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) {
231 // The test empty extension has no permissions, therefore it should not get 231 // The test empty extension has no permissions, therefore it should not get
232 // tab data in the function result. 232 // tab data in the function result.
233 scoped_refptr<TabsUpdateFunction> update_tab_function( 233 scoped_refptr<TabsUpdateFunction> update_tab_function(
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 int window_id = ExtensionTabUtil::GetWindowId(browser()); 397 int window_id = ExtensionTabUtil::GetWindowId(browser());
398 398
399 // Get tabs in the 'current' window called from non-focused browser. 399 // Get tabs in the 'current' window called from non-focused browser.
400 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); 400 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
401 function->set_extension(utils::CreateEmptyExtension().get()); 401 function->set_extension(utils::CreateEmptyExtension().get());
402 scoped_ptr<base::ListValue> result(utils::ToList( 402 scoped_ptr<base::ListValue> result(utils::ToList(
403 utils::RunFunctionAndReturnSingleResult(function.get(), 403 utils::RunFunctionAndReturnSingleResult(function.get(),
404 "[{\"currentWindow\":true}]", 404 "[{\"currentWindow\":true}]",
405 browser()))); 405 browser())));
406 406
407 ListValue* result_tabs = result.get(); 407 base::ListValue* result_tabs = result.get();
408 // We should have one initial tab and one added tab. 408 // We should have one initial tab and one added tab.
409 EXPECT_EQ(2u, result_tabs->GetSize()); 409 EXPECT_EQ(2u, result_tabs->GetSize());
410 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 410 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
411 DictionaryValue* result_tab = NULL; 411 base::DictionaryValue* result_tab = NULL;
412 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 412 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
413 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 413 EXPECT_EQ(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
414 } 414 }
415 415
416 // Get tabs NOT in the 'current' window called from non-focused browser. 416 // Get tabs NOT in the 'current' window called from non-focused browser.
417 function = new TabsQueryFunction(); 417 function = new TabsQueryFunction();
418 function->set_extension(utils::CreateEmptyExtension().get()); 418 function->set_extension(utils::CreateEmptyExtension().get());
419 result.reset(utils::ToList( 419 result.reset(utils::ToList(
420 utils::RunFunctionAndReturnSingleResult(function.get(), 420 utils::RunFunctionAndReturnSingleResult(function.get(),
421 "[{\"currentWindow\":false}]", 421 "[{\"currentWindow\":false}]",
422 browser()))); 422 browser())));
423 423
424 result_tabs = result.get(); 424 result_tabs = result.get();
425 // We should have one tab for each extra window. 425 // We should have one tab for each extra window.
426 EXPECT_EQ(kExtraWindows, result_tabs->GetSize()); 426 EXPECT_EQ(kExtraWindows, result_tabs->GetSize());
427 for (size_t i = 0; i < kExtraWindows; ++i) { 427 for (size_t i = 0; i < kExtraWindows; ++i) {
428 DictionaryValue* result_tab = NULL; 428 base::DictionaryValue* result_tab = NULL;
429 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 429 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
430 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey)); 430 EXPECT_NE(window_id, utils::GetInteger(result_tab, keys::kWindowIdKey));
431 } 431 }
432 } 432 }
433 433
434 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { 434 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) {
435 // Test creates new popup window, closes it right away and then tries to open 435 // Test creates new popup window, closes it right away and then tries to open
436 // a new tab in it. Tab should not be opened in the popup window, but in a 436 // a new tab in it. Tab should not be opened in the popup window, but in a
437 // tabbed browser window. 437 // tabbed browser window.
438 Browser* popup_browser = new Browser( 438 Browser* popup_browser = new Browser(
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 // Duplicate tab id should be different from the original tab id. 584 // Duplicate tab id should be different from the original tab id.
585 EXPECT_NE(tab_id, duplicate_tab_id); 585 EXPECT_NE(tab_id, duplicate_tab_id);
586 EXPECT_EQ(window_id, duplicate_tab_window_id); 586 EXPECT_EQ(window_id, duplicate_tab_window_id);
587 EXPECT_EQ(tab_index + 1, duplicate_tab_index); 587 EXPECT_EQ(tab_index + 1, duplicate_tab_index);
588 // The test empty extension has no permissions, therefore |duplicate_result| 588 // The test empty extension has no permissions, therefore |duplicate_result|
589 // should not contain url, title, and faviconUrl in the function result. 589 // should not contain url, title, and faviconUrl in the function result.
590 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get())); 590 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
591 } 591 }
592 592
593 } // namespace extensions 593 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698