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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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 (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 #include <limits.h> 5 #include <limits.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory>
9 #include <string> 10 #include <string>
10 11
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/pattern.h" 13 #include "base/strings/pattern.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/apps/app_browsertest_util.h" 19 #include "chrome/browser/apps/app_browsertest_util.h"
20 #include "chrome/browser/devtools/devtools_window_testing.h" 20 #include "chrome/browser/devtools/devtools_window_testing.h"
21 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 21 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
22 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 22 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 // Basic window details. 115 // Basic window details.
116 gfx::Rect bounds; 116 gfx::Rect bounds;
117 if (browser()->window()->IsMinimized()) 117 if (browser()->window()->IsMinimized())
118 bounds = browser()->window()->GetRestoredBounds(); 118 bounds = browser()->window()->GetRestoredBounds();
119 else 119 else
120 bounds = browser()->window()->GetBounds(); 120 bounds = browser()->window()->GetBounds();
121 121
122 function = new WindowsGetFunction(); 122 function = new WindowsGetFunction();
123 function->set_extension(extension.get()); 123 function->set_extension(extension.get());
124 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 124 std::unique_ptr<base::DictionaryValue> result(
125 utils::RunFunctionAndReturnSingleResult( 125 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
126 function.get(), 126 function.get(), base::StringPrintf("[%u]", window_id), browser())));
127 base::StringPrintf("[%u]", window_id),
128 browser())));
129 EXPECT_EQ(window_id, GetWindowId(result.get())); 127 EXPECT_EQ(window_id, GetWindowId(result.get()));
130 EXPECT_FALSE(api_test_utils::GetBoolean(result.get(), "incognito")); 128 EXPECT_FALSE(api_test_utils::GetBoolean(result.get(), "incognito"));
131 EXPECT_EQ("normal", api_test_utils::GetString(result.get(), "type")); 129 EXPECT_EQ("normal", api_test_utils::GetString(result.get(), "type"));
132 EXPECT_EQ(bounds.x(), api_test_utils::GetInteger(result.get(), "left")); 130 EXPECT_EQ(bounds.x(), api_test_utils::GetInteger(result.get(), "left"));
133 EXPECT_EQ(bounds.y(), api_test_utils::GetInteger(result.get(), "top")); 131 EXPECT_EQ(bounds.y(), api_test_utils::GetInteger(result.get(), "top"));
134 EXPECT_EQ(bounds.width(), api_test_utils::GetInteger(result.get(), "width")); 132 EXPECT_EQ(bounds.width(), api_test_utils::GetInteger(result.get(), "width"));
135 EXPECT_EQ(bounds.height(), 133 EXPECT_EQ(bounds.height(),
136 api_test_utils::GetInteger(result.get(), "height")); 134 api_test_utils::GetInteger(result.get(), "height"));
137 135
138 // With "populate" enabled. 136 // With "populate" enabled.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) { 217 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) {
220 int window_id = ExtensionTabUtil::GetWindowId(browser()); 218 int window_id = ExtensionTabUtil::GetWindowId(browser());
221 Browser* new_browser = CreateBrowser(browser()->profile()); 219 Browser* new_browser = CreateBrowser(browser()->profile());
222 int new_id = ExtensionTabUtil::GetWindowId(new_browser); 220 int new_id = ExtensionTabUtil::GetWindowId(new_browser);
223 221
224 // Get the current window using new_browser. 222 // Get the current window using new_browser.
225 scoped_refptr<WindowsGetCurrentFunction> function = 223 scoped_refptr<WindowsGetCurrentFunction> function =
226 new WindowsGetCurrentFunction(); 224 new WindowsGetCurrentFunction();
227 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 225 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
228 function->set_extension(extension.get()); 226 function->set_extension(extension.get());
229 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 227 std::unique_ptr<base::DictionaryValue> result(
230 utils::RunFunctionAndReturnSingleResult(function.get(), 228 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
231 "[]", 229 function.get(), "[]", new_browser)));
232 new_browser)));
233 230
234 // The id should match the window id of the browser instance that was passed 231 // The id should match the window id of the browser instance that was passed
235 // to RunFunctionAndReturnSingleResult. 232 // to RunFunctionAndReturnSingleResult.
236 EXPECT_EQ(new_id, GetWindowId(result.get())); 233 EXPECT_EQ(new_id, GetWindowId(result.get()));
237 base::ListValue* tabs = nullptr; 234 base::ListValue* tabs = nullptr;
238 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs)); 235 EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
239 236
240 // Get the current window using the old window and make the tabs populated. 237 // Get the current window using the old window and make the tabs populated.
241 function = new WindowsGetCurrentFunction(); 238 function = new WindowsGetCurrentFunction();
242 function->set_extension(extension.get()); 239 function->set_extension(extension.get());
(...skipping 30 matching lines...) Expand all
273 AppWindow* app_window = CreateTestAppWindow("{}"); 270 AppWindow* app_window = CreateTestAppWindow("{}");
274 271
275 // Undocked DevTools window should not be accessible, unless allWindowTypes is 272 // Undocked DevTools window should not be accessible, unless allWindowTypes is
276 // set to true. 273 // set to true.
277 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 274 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
278 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 275 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
279 276
280 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); 277 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction();
281 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 278 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
282 function->set_extension(extension.get()); 279 function->set_extension(extension.get());
283 scoped_ptr<base::ListValue> result(utils::ToList( 280 std::unique_ptr<base::ListValue> result(
284 utils::RunFunctionAndReturnSingleResult(function.get(), 281 utils::ToList(utils::RunFunctionAndReturnSingleResult(function.get(),
285 "[]", 282 "[]", browser())));
286 browser())));
287 283
288 base::ListValue* windows = result.get(); 284 base::ListValue* windows = result.get();
289 EXPECT_EQ(window_ids.size(), windows->GetSize()); 285 EXPECT_EQ(window_ids.size(), windows->GetSize());
290 for (size_t i = 0; i < windows->GetSize(); ++i) { 286 for (size_t i = 0; i < windows->GetSize(); ++i) {
291 base::DictionaryValue* result_window = nullptr; 287 base::DictionaryValue* result_window = nullptr;
292 EXPECT_TRUE(windows->GetDictionary(i, &result_window)); 288 EXPECT_TRUE(windows->GetDictionary(i, &result_window));
293 result_ids.insert(GetWindowId(result_window)); 289 result_ids.insert(GetWindowId(result_window));
294 290
295 // "populate" was not passed in so tabs are not populated. 291 // "populate" was not passed in so tabs are not populated.
296 base::ListValue* tabs = nullptr; 292 base::ListValue* tabs = nullptr;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 340
345 // Undocked DevTools window should be accessible too. 341 // Undocked DevTools window should be accessible too.
346 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 342 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
347 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 343 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
348 window_ids.insert(ExtensionTabUtil::GetWindowId( 344 window_ids.insert(ExtensionTabUtil::GetWindowId(
349 DevToolsWindowTesting::Get(devtools)->browser())); 345 DevToolsWindowTesting::Get(devtools)->browser()));
350 346
351 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); 347 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction();
352 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 348 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
353 function->set_extension(extension.get()); 349 function->set_extension(extension.get());
354 scoped_ptr<base::ListValue> result( 350 std::unique_ptr<base::ListValue> result(
355 utils::ToList(utils::RunFunctionAndReturnSingleResult( 351 utils::ToList(utils::RunFunctionAndReturnSingleResult(
356 function.get(), 352 function.get(),
357 "[{\"windowTypes\": [\"app\", \"devtools\", \"normal\", \"panel\", " 353 "[{\"windowTypes\": [\"app\", \"devtools\", \"normal\", \"panel\", "
358 "\"popup\"]}]", 354 "\"popup\"]}]",
359 browser()))); 355 browser())));
360 356
361 base::ListValue* windows = result.get(); 357 base::ListValue* windows = result.get();
362 EXPECT_EQ(window_ids.size(), windows->GetSize()); 358 EXPECT_EQ(window_ids.size(), windows->GetSize());
363 for (size_t i = 0; i < windows->GetSize(); ++i) { 359 for (size_t i = 0; i < windows->GetSize(); ++i) {
364 base::DictionaryValue* result_window = nullptr; 360 base::DictionaryValue* result_window = nullptr;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) { 401 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) {
406 // The test empty extension has no permissions, therefore it should not get 402 // The test empty extension has no permissions, therefore it should not get
407 // tab data in the function result. 403 // tab data in the function result.
408 scoped_refptr<TabsUpdateFunction> update_tab_function( 404 scoped_refptr<TabsUpdateFunction> update_tab_function(
409 new TabsUpdateFunction()); 405 new TabsUpdateFunction());
410 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); 406 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension());
411 update_tab_function->set_extension(empty_extension.get()); 407 update_tab_function->set_extension(empty_extension.get());
412 // Without a callback the function will not generate a result. 408 // Without a callback the function will not generate a result.
413 update_tab_function->set_has_callback(true); 409 update_tab_function->set_has_callback(true);
414 410
415 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 411 std::unique_ptr<base::DictionaryValue> result(
416 utils::RunFunctionAndReturnSingleResult( 412 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
417 update_tab_function.get(), 413 update_tab_function.get(),
418 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", 414 "[null, {\"url\": \"about:blank\", \"pinned\": true}]", browser())));
419 browser())));
420 // The url is stripped since the extension does not have tab permissions. 415 // The url is stripped since the extension does not have tab permissions.
421 EXPECT_FALSE(result->HasKey("url")); 416 EXPECT_FALSE(result->HasKey("url"));
422 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "pinned")); 417 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "pinned"));
423 } 418 }
424 419
425 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 420 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
426 DefaultToIncognitoWhenItIsForced) { 421 DefaultToIncognitoWhenItIsForced) {
427 static const char kArgsWithoutExplicitIncognitoParam[] = 422 static const char kArgsWithoutExplicitIncognitoParam[] =
428 "[{\"url\": \"about:blank\"}]"; 423 "[{\"url\": \"about:blank\"}]";
429 // Force Incognito mode. 424 // Force Incognito mode.
430 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 425 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
431 IncognitoModePrefs::FORCED); 426 IncognitoModePrefs::FORCED);
432 // Run without an explicit "incognito" param. 427 // Run without an explicit "incognito" param.
433 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); 428 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
434 function->SetRenderFrameHost( 429 function->SetRenderFrameHost(
435 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); 430 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame());
436 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 431 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
437 function->set_extension(extension.get()); 432 function->set_extension(extension.get());
438 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 433 std::unique_ptr<base::DictionaryValue> result(
439 utils::RunFunctionAndReturnSingleResult( 434 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
440 function.get(), 435 function.get(), kArgsWithoutExplicitIncognitoParam, browser(),
441 kArgsWithoutExplicitIncognitoParam,
442 browser(),
443 utils::INCLUDE_INCOGNITO))); 436 utils::INCLUDE_INCOGNITO)));
444 437
445 // Make sure it is a new(different) window. 438 // Make sure it is a new(different) window.
446 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 439 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
447 GetWindowId(result.get())); 440 GetWindowId(result.get()));
448 // ... and it is incognito. 441 // ... and it is incognito.
449 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "incognito")); 442 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "incognito"));
450 443
451 // Now try creating a window from incognito window. 444 // Now try creating a window from incognito window.
452 Browser* incognito_browser = CreateIncognitoBrowser(); 445 Browser* incognito_browser = CreateIncognitoBrowser();
(...skipping 18 matching lines...) Expand all
471 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, 464 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
472 DefaultToIncognitoWhenItIsForcedAndNoArgs) { 465 DefaultToIncognitoWhenItIsForcedAndNoArgs) {
473 static const char kEmptyArgs[] = "[]"; 466 static const char kEmptyArgs[] = "[]";
474 // Force Incognito mode. 467 // Force Incognito mode.
475 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), 468 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
476 IncognitoModePrefs::FORCED); 469 IncognitoModePrefs::FORCED);
477 // Run without an explicit "incognito" param. 470 // Run without an explicit "incognito" param.
478 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); 471 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction();
479 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 472 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
480 function->set_extension(extension.get()); 473 function->set_extension(extension.get());
481 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 474 std::unique_ptr<base::DictionaryValue> result(
482 utils::RunFunctionAndReturnSingleResult(function.get(), 475 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
483 kEmptyArgs, 476 function.get(), kEmptyArgs, browser(), utils::INCLUDE_INCOGNITO)));
484 browser(),
485 utils::INCLUDE_INCOGNITO)));
486 477
487 // Make sure it is a new(different) window. 478 // Make sure it is a new(different) window.
488 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()), 479 EXPECT_NE(ExtensionTabUtil::GetWindowId(browser()),
489 GetWindowId(result.get())); 480 GetWindowId(result.get()));
490 // ... and it is incognito. 481 // ... and it is incognito.
491 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "incognito")); 482 EXPECT_TRUE(api_test_utils::GetBoolean(result.get(), "incognito"));
492 483
493 // Now try creating a window from incognito window. 484 // Now try creating a window from incognito window.
494 Browser* incognito_browser = CreateIncognitoBrowser(); 485 Browser* incognito_browser = CreateIncognitoBrowser();
495 // Run without an explicit "incognito" param. 486 // Run without an explicit "incognito" param.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 for (size_t i = 0; i < kExtraWindows; ++i) 556 for (size_t i = 0; i < kExtraWindows; ++i)
566 CreateBrowser(browser()->profile()); 557 CreateBrowser(browser()->profile());
567 558
568 GURL url(url::kAboutBlankURL); 559 GURL url(url::kAboutBlankURL);
569 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_LINK); 560 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_LINK);
570 int window_id = ExtensionTabUtil::GetWindowId(browser()); 561 int window_id = ExtensionTabUtil::GetWindowId(browser());
571 562
572 // Get tabs in the 'current' window called from non-focused browser. 563 // Get tabs in the 'current' window called from non-focused browser.
573 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); 564 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
574 function->set_extension(test_util::CreateEmptyExtension().get()); 565 function->set_extension(test_util::CreateEmptyExtension().get());
575 scoped_ptr<base::ListValue> result(utils::ToList( 566 std::unique_ptr<base::ListValue> result(
576 utils::RunFunctionAndReturnSingleResult(function.get(), 567 utils::ToList(utils::RunFunctionAndReturnSingleResult(
577 "[{\"currentWindow\":true}]", 568 function.get(), "[{\"currentWindow\":true}]", browser())));
578 browser())));
579 569
580 base::ListValue* result_tabs = result.get(); 570 base::ListValue* result_tabs = result.get();
581 // We should have one initial tab and one added tab. 571 // We should have one initial tab and one added tab.
582 EXPECT_EQ(2u, result_tabs->GetSize()); 572 EXPECT_EQ(2u, result_tabs->GetSize());
583 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 573 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
584 base::DictionaryValue* result_tab = nullptr; 574 base::DictionaryValue* result_tab = nullptr;
585 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 575 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
586 EXPECT_EQ(window_id, GetTabWindowId(result_tab)); 576 EXPECT_EQ(window_id, GetTabWindowId(result_tab));
587 } 577 }
588 578
(...skipping 24 matching lines...) Expand all
613 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser)); 603 window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser));
614 } 604 }
615 605
616 // Undocked DevTools window should not be accessible. 606 // Undocked DevTools window should not be accessible.
617 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 607 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
618 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 608 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
619 609
620 // Get tabs in the 'current' window called from non-focused browser. 610 // Get tabs in the 'current' window called from non-focused browser.
621 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction(); 611 scoped_refptr<TabsQueryFunction> function = new TabsQueryFunction();
622 function->set_extension(test_util::CreateEmptyExtension().get()); 612 function->set_extension(test_util::CreateEmptyExtension().get());
623 scoped_ptr<base::ListValue> result(utils::ToList( 613 std::unique_ptr<base::ListValue> result(
624 utils::RunFunctionAndReturnSingleResult(function.get(), 614 utils::ToList(utils::RunFunctionAndReturnSingleResult(
625 "[{}]", 615 function.get(), "[{}]", browser())));
626 browser())));
627 616
628 std::set<int> result_ids; 617 std::set<int> result_ids;
629 base::ListValue* result_tabs = result.get(); 618 base::ListValue* result_tabs = result.get();
630 // We should have one tab per browser except for DevTools. 619 // We should have one tab per browser except for DevTools.
631 EXPECT_EQ(kNumWindows, result_tabs->GetSize()); 620 EXPECT_EQ(kNumWindows, result_tabs->GetSize());
632 for (size_t i = 0; i < result_tabs->GetSize(); ++i) { 621 for (size_t i = 0; i < result_tabs->GetSize(); ++i) {
633 base::DictionaryValue* result_tab = nullptr; 622 base::DictionaryValue* result_tab = nullptr;
634 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); 623 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab));
635 result_ids.insert(GetTabWindowId(result_tab)); 624 result_ids.insert(GetTabWindowId(result_tab));
636 } 625 }
(...skipping 13 matching lines...) Expand all
650 639
651 scoped_refptr<TabsCreateFunction> create_tab_function( 640 scoped_refptr<TabsCreateFunction> create_tab_function(
652 new TabsCreateFunction()); 641 new TabsCreateFunction());
653 create_tab_function->set_extension(test_util::CreateEmptyExtension().get()); 642 create_tab_function->set_extension(test_util::CreateEmptyExtension().get());
654 // Without a callback the function will not generate a result. 643 // Without a callback the function will not generate a result.
655 create_tab_function->set_has_callback(true); 644 create_tab_function->set_has_callback(true);
656 645
657 static const char kNewBlankTabArgs[] = 646 static const char kNewBlankTabArgs[] =
658 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; 647 "[{\"url\": \"about:blank\", \"windowId\": %u}]";
659 648
660 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 649 std::unique_ptr<base::DictionaryValue> result(
661 utils::RunFunctionAndReturnSingleResult( 650 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
662 create_tab_function.get(), 651 create_tab_function.get(),
663 base::StringPrintf(kNewBlankTabArgs, window_id), 652 base::StringPrintf(kNewBlankTabArgs, window_id), browser())));
664 browser())));
665 653
666 EXPECT_NE(window_id, GetTabWindowId(result.get())); 654 EXPECT_NE(window_id, GetTabWindowId(result.get()));
667 } 655 }
668 656
669 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { 657 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) {
670 int window_id = ExtensionTabUtil::GetWindowId(browser()); 658 int window_id = ExtensionTabUtil::GetWindowId(browser());
671 659
672 static const char kArgsMinimizedWithFocus[] = 660 static const char kArgsMinimizedWithFocus[] =
673 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; 661 "[%u, {\"state\": \"minimized\", \"focused\": true}]";
674 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction(); 662 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateAppWindowSizeConstraint) { 702 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateAppWindowSizeConstraint) {
715 AppWindow* app_window = CreateTestAppWindow( 703 AppWindow* app_window = CreateTestAppWindow(
716 "{\"outerBounds\": " 704 "{\"outerBounds\": "
717 "{\"width\": 300, \"height\": 300," 705 "{\"width\": 300, \"height\": 300,"
718 " \"minWidth\": 200, \"minHeight\": 200," 706 " \"minWidth\": 200, \"minHeight\": 200,"
719 " \"maxWidth\": 400, \"maxHeight\": 400}}"); 707 " \"maxWidth\": 400, \"maxHeight\": 400}}");
720 708
721 scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction(); 709 scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction();
722 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension().get()); 710 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension().get());
723 get_function->set_extension(extension.get()); 711 get_function->set_extension(extension.get());
724 scoped_ptr<base::DictionaryValue> result( 712 std::unique_ptr<base::DictionaryValue> result(
725 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 713 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
726 get_function.get(), 714 get_function.get(),
727 base::StringPrintf("[%u, {\"windowTypes\": [\"app\"]}]", 715 base::StringPrintf("[%u, {\"windowTypes\": [\"app\"]}]",
728 app_window->session_id().id()), 716 app_window->session_id().id()),
729 browser()))); 717 browser())));
730 718
731 EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "width")); 719 EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "width"));
732 EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "height")); 720 EXPECT_EQ(300, api_test_utils::GetInteger(result.get(), "height"));
733 721
734 // Verify the min width/height of the application window are 722 // Verify the min width/height of the application window are
(...skipping 25 matching lines...) Expand all
760 CloseAppWindow(app_window); 748 CloseAppWindow(app_window);
761 } 749 }
762 750
763 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateDevToolsWindow) { 751 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateDevToolsWindow) {
764 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 752 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
765 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 753 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
766 754
767 scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction(); 755 scoped_refptr<WindowsGetFunction> get_function = new WindowsGetFunction();
768 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension().get()); 756 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension().get());
769 get_function->set_extension(extension.get()); 757 get_function->set_extension(extension.get());
770 scoped_ptr<base::DictionaryValue> result( 758 std::unique_ptr<base::DictionaryValue> result(
771 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 759 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
772 get_function.get(), 760 get_function.get(),
773 base::StringPrintf( 761 base::StringPrintf(
774 "[%u, {\"windowTypes\": [\"devtools\"]}]", 762 "[%u, {\"windowTypes\": [\"devtools\"]}]",
775 ExtensionTabUtil::GetWindowId( 763 ExtensionTabUtil::GetWindowId(
776 DevToolsWindowTesting::Get(devtools)->browser())), 764 DevToolsWindowTesting::Get(devtools)->browser())),
777 browser()))); 765 browser())));
778 766
779 // Verify the updating width/height works. 767 // Verify the updating width/height works.
780 int32_t new_width = api_test_utils::GetInteger(result.get(), "width") - 50; 768 int32_t new_width = api_test_utils::GetInteger(result.get(), "width") - 50;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 NoDevtoolsAndAppWindows) { 935 NoDevtoolsAndAppWindows) {
948 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 936 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
949 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 937 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
950 { 938 {
951 int devtools_window_id = ExtensionTabUtil::GetWindowId( 939 int devtools_window_id = ExtensionTabUtil::GetWindowId(
952 DevToolsWindowTesting::Get(devtools)->browser()); 940 DevToolsWindowTesting::Get(devtools)->browser());
953 ActivateBrowserWindow(DevToolsWindowTesting::Get(devtools)->browser()); 941 ActivateBrowserWindow(DevToolsWindowTesting::Get(devtools)->browser());
954 942
955 scoped_refptr<WindowsGetLastFocusedFunction> function = 943 scoped_refptr<WindowsGetLastFocusedFunction> function =
956 new WindowsGetLastFocusedFunction(); 944 new WindowsGetLastFocusedFunction();
957 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 945 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
958 RunFunction(function.get(), "[{\"populate\": true}]"))); 946 RunFunction(function.get(), "[{\"populate\": true}]")));
959 EXPECT_NE(devtools_window_id, 947 EXPECT_NE(devtools_window_id,
960 api_test_utils::GetInteger(result.get(), "id")); 948 api_test_utils::GetInteger(result.get(), "id"));
961 } 949 }
962 950
963 AppWindow* app_window = CreateTestAppWindow( 951 AppWindow* app_window = CreateTestAppWindow(
964 "{\"outerBounds\": " 952 "{\"outerBounds\": "
965 "{\"width\": 300, \"height\": 300," 953 "{\"width\": 300, \"height\": 300,"
966 " \"minWidth\": 200, \"minHeight\": 200," 954 " \"minWidth\": 200, \"minHeight\": 200,"
967 " \"maxWidth\": 400, \"maxHeight\": 400}}"); 955 " \"maxWidth\": 400, \"maxHeight\": 400}}");
968 { 956 {
969 ActivateAppWindow(app_window); 957 ActivateAppWindow(app_window);
970 958
971 scoped_refptr<WindowsGetLastFocusedFunction> get_current_app_function = 959 scoped_refptr<WindowsGetLastFocusedFunction> get_current_app_function =
972 new WindowsGetLastFocusedFunction(); 960 new WindowsGetLastFocusedFunction();
973 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 961 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
974 RunFunction(get_current_app_function.get(), "[{\"populate\": true}]"))); 962 RunFunction(get_current_app_function.get(), "[{\"populate\": true}]")));
975 int app_window_id = app_window->session_id().id(); 963 int app_window_id = app_window->session_id().id();
976 EXPECT_NE(app_window_id, api_test_utils::GetInteger(result.get(), "id")); 964 EXPECT_NE(app_window_id, api_test_utils::GetInteger(result.get(), "id"));
977 } 965 }
978 966
979 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); 967 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
980 CloseAppWindow(app_window); 968 CloseAppWindow(app_window);
981 } 969 }
982 970
983 IN_PROC_BROWSER_TEST_F(ExtensionWindowLastFocusedTest, 971 IN_PROC_BROWSER_TEST_F(ExtensionWindowLastFocusedTest,
984 NoTabIdForDevToolsAndAppWindows) { 972 NoTabIdForDevToolsAndAppWindows) {
985 Browser* normal_browser = CreateBrowserWithEmptyTab(false); 973 Browser* normal_browser = CreateBrowserWithEmptyTab(false);
986 { 974 {
987 ActivateBrowserWindow(normal_browser); 975 ActivateBrowserWindow(normal_browser);
988 976
989 scoped_refptr<WindowsGetLastFocusedFunction> function = 977 scoped_refptr<WindowsGetLastFocusedFunction> function =
990 new WindowsGetLastFocusedFunction(); 978 new WindowsGetLastFocusedFunction();
991 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 979 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
992 RunFunction(function.get(), "[{\"populate\": true}]"))); 980 RunFunction(function.get(), "[{\"populate\": true}]")));
993 int normal_browser_window_id = 981 int normal_browser_window_id =
994 ExtensionTabUtil::GetWindowId(normal_browser); 982 ExtensionTabUtil::GetWindowId(normal_browser);
995 EXPECT_EQ(normal_browser_window_id, 983 EXPECT_EQ(normal_browser_window_id,
996 api_test_utils::GetInteger(result.get(), "id")); 984 api_test_utils::GetInteger(result.get(), "id"));
997 EXPECT_NE(-1, GetTabId(result.get())); 985 EXPECT_NE(-1, GetTabId(result.get()));
998 EXPECT_EQ("normal", api_test_utils::GetString(result.get(), "type")); 986 EXPECT_EQ("normal", api_test_utils::GetString(result.get(), "type"));
999 } 987 }
1000 988
1001 Browser* popup_browser = CreateBrowserWithEmptyTab(true); 989 Browser* popup_browser = CreateBrowserWithEmptyTab(true);
1002 { 990 {
1003 ActivateBrowserWindow(popup_browser); 991 ActivateBrowserWindow(popup_browser);
1004 992
1005 scoped_refptr<WindowsGetLastFocusedFunction> function = 993 scoped_refptr<WindowsGetLastFocusedFunction> function =
1006 new WindowsGetLastFocusedFunction(); 994 new WindowsGetLastFocusedFunction();
1007 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 995 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
1008 RunFunction(function.get(), "[{\"populate\": true}]"))); 996 RunFunction(function.get(), "[{\"populate\": true}]")));
1009 int popup_browser_window_id = ExtensionTabUtil::GetWindowId(popup_browser); 997 int popup_browser_window_id = ExtensionTabUtil::GetWindowId(popup_browser);
1010 EXPECT_EQ(popup_browser_window_id, 998 EXPECT_EQ(popup_browser_window_id,
1011 api_test_utils::GetInteger(result.get(), "id")); 999 api_test_utils::GetInteger(result.get(), "id"));
1012 EXPECT_NE(-1, GetTabId(result.get())); 1000 EXPECT_NE(-1, GetTabId(result.get()));
1013 EXPECT_EQ("popup", api_test_utils::GetString(result.get(), "type")); 1001 EXPECT_EQ("popup", api_test_utils::GetString(result.get(), "type"));
1014 } 1002 }
1015 1003
1016 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 1004 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
1017 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 1005 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
1018 { 1006 {
1019 ActivateBrowserWindow(DevToolsWindowTesting::Get(devtools)->browser()); 1007 ActivateBrowserWindow(DevToolsWindowTesting::Get(devtools)->browser());
1020 1008
1021 scoped_refptr<WindowsGetLastFocusedFunction> function = 1009 scoped_refptr<WindowsGetLastFocusedFunction> function =
1022 new WindowsGetLastFocusedFunction(); 1010 new WindowsGetLastFocusedFunction();
1023 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary(RunFunction( 1011 std::unique_ptr<base::DictionaryValue> result(
1024 function.get(), 1012 utils::ToDictionary(RunFunction(
1025 "[{\"populate\": true, \"windowTypes\": [ \"devtools\" ]}]"))); 1013 function.get(),
1014 "[{\"populate\": true, \"windowTypes\": [ \"devtools\" ]}]")));
1026 int devtools_window_id = ExtensionTabUtil::GetWindowId( 1015 int devtools_window_id = ExtensionTabUtil::GetWindowId(
1027 DevToolsWindowTesting::Get(devtools)->browser()); 1016 DevToolsWindowTesting::Get(devtools)->browser());
1028 EXPECT_EQ(devtools_window_id, 1017 EXPECT_EQ(devtools_window_id,
1029 api_test_utils::GetInteger(result.get(), "id")); 1018 api_test_utils::GetInteger(result.get(), "id"));
1030 EXPECT_EQ(-1, GetTabId(result.get())); 1019 EXPECT_EQ(-1, GetTabId(result.get()));
1031 EXPECT_EQ("devtools", api_test_utils::GetString(result.get(), "type")); 1020 EXPECT_EQ("devtools", api_test_utils::GetString(result.get(), "type"));
1032 } 1021 }
1033 1022
1034 AppWindow* app_window = CreateTestAppWindow( 1023 AppWindow* app_window = CreateTestAppWindow(
1035 "{\"outerBounds\": " 1024 "{\"outerBounds\": "
1036 "{\"width\": 300, \"height\": 300," 1025 "{\"width\": 300, \"height\": 300,"
1037 " \"minWidth\": 200, \"minHeight\": 200," 1026 " \"minWidth\": 200, \"minHeight\": 200,"
1038 " \"maxWidth\": 400, \"maxHeight\": 400}}"); 1027 " \"maxWidth\": 400, \"maxHeight\": 400}}");
1039 { 1028 {
1040 ActivateAppWindow(app_window); 1029 ActivateAppWindow(app_window);
1041 1030
1042 scoped_refptr<WindowsGetLastFocusedFunction> get_current_app_function = 1031 scoped_refptr<WindowsGetLastFocusedFunction> get_current_app_function =
1043 new WindowsGetLastFocusedFunction(); 1032 new WindowsGetLastFocusedFunction();
1044 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( 1033 std::unique_ptr<base::DictionaryValue> result(utils::ToDictionary(
1045 RunFunction(get_current_app_function.get(), 1034 RunFunction(get_current_app_function.get(),
1046 "[{\"populate\": true, \"windowTypes\": [ \"app\" ]}]"))); 1035 "[{\"populate\": true, \"windowTypes\": [ \"app\" ]}]")));
1047 int app_window_id = app_window->session_id().id(); 1036 int app_window_id = app_window->session_id().id();
1048 EXPECT_EQ(app_window_id, api_test_utils::GetInteger(result.get(), "id")); 1037 EXPECT_EQ(app_window_id, api_test_utils::GetInteger(result.get(), "id"));
1049 EXPECT_EQ(-1, GetTabId(result.get())); 1038 EXPECT_EQ(-1, GetTabId(result.get()));
1050 EXPECT_EQ("app", api_test_utils::GetString(result.get(), "type")); 1039 EXPECT_EQ("app", api_test_utils::GetString(result.get(), "type"));
1051 } 1040 }
1052 1041
1053 chrome::CloseWindow(normal_browser); 1042 chrome::CloseWindow(normal_browser);
1054 chrome::CloseWindow(popup_browser); 1043 chrome::CloseWindow(popup_browser);
1055 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); 1044 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
1056 CloseAppWindow(app_window); 1045 CloseAppWindow(app_window);
1057 } 1046 }
1058 #endif // !defined(OS_MACOSX) 1047 #endif // !defined(OS_MACOSX)
1059 1048
1060 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { 1049 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) {
1061 #if defined(OS_MACOSX) 1050 #if defined(OS_MACOSX)
1062 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; 1051 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
1063 #endif 1052 #endif
1064 1053
1065 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); 1054 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
1066 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 1055 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
1067 function->set_extension(extension.get()); 1056 function->set_extension(extension.get());
1068 1057
1069 scoped_ptr<base::DictionaryValue> result( 1058 std::unique_ptr<base::DictionaryValue> result(
1070 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 1059 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
1071 function.get(), "[{\"state\": \"minimized\"}]", browser(), 1060 function.get(), "[{\"state\": \"minimized\"}]", browser(),
1072 utils::INCLUDE_INCOGNITO))); 1061 utils::INCLUDE_INCOGNITO)));
1073 int window_id = GetWindowId(result.get()); 1062 int window_id = GetWindowId(result.get());
1074 std::string error; 1063 std::string error;
1075 Browser* new_window = ExtensionTabUtil::GetBrowserFromWindowID( 1064 Browser* new_window = ExtensionTabUtil::GetBrowserFromWindowID(
1076 function.get(), window_id, &error); 1065 function.get(), window_id, &error);
1077 EXPECT_TRUE(error.empty()); 1066 EXPECT_TRUE(error.empty());
1078 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) 1067 #if !defined(OS_LINUX) || defined(OS_CHROMEOS)
1079 // DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update 1068 // DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 false); 1132 false);
1144 content::WebContents* web_contents = browser()->OpenURL(params); 1133 content::WebContents* web_contents = browser()->OpenURL(params);
1145 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 1134 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
1146 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); 1135 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
1147 int tab_index = -1; 1136 int tab_index = -1;
1148 TabStripModel* tab_strip; 1137 TabStripModel* tab_strip;
1149 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); 1138 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
1150 1139
1151 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function( 1140 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function(
1152 new TabsDuplicateFunction()); 1141 new TabsDuplicateFunction());
1153 scoped_ptr<base::DictionaryValue> test_extension_value( 1142 std::unique_ptr<base::DictionaryValue> test_extension_value(
1154 api_test_utils::ParseDictionary( 1143 api_test_utils::ParseDictionary(
1155 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": " 1144 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": "
1156 "[\"tabs\"]}")); 1145 "[\"tabs\"]}"));
1157 scoped_refptr<Extension> empty_tab_extension( 1146 scoped_refptr<Extension> empty_tab_extension(
1158 api_test_utils::CreateExtension(test_extension_value.get())); 1147 api_test_utils::CreateExtension(test_extension_value.get()));
1159 duplicate_tab_function->set_extension(empty_tab_extension.get()); 1148 duplicate_tab_function->set_extension(empty_tab_extension.get());
1160 duplicate_tab_function->set_has_callback(true); 1149 duplicate_tab_function->set_has_callback(true);
1161 1150
1162 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( 1151 std::unique_ptr<base::DictionaryValue> duplicate_result(
1163 utils::RunFunctionAndReturnSingleResult( 1152 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
1164 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), 1153 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id),
1165 browser()))); 1154 browser())));
1166 1155
1167 int duplicate_tab_id = GetTabId(duplicate_result.get()); 1156 int duplicate_tab_id = GetTabId(duplicate_result.get());
1168 int duplicate_tab_window_id = GetTabWindowId(duplicate_result.get()); 1157 int duplicate_tab_window_id = GetTabWindowId(duplicate_result.get());
1169 int duplicate_tab_index = 1158 int duplicate_tab_index =
1170 api_test_utils::GetInteger(duplicate_result.get(), "index"); 1159 api_test_utils::GetInteger(duplicate_result.get(), "index");
1171 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); 1160 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType());
1172 // Duplicate tab id should be different from the original tab id. 1161 // Duplicate tab id should be different from the original tab id.
1173 EXPECT_NE(tab_id, duplicate_tab_id); 1162 EXPECT_NE(tab_id, duplicate_tab_id);
(...skipping 17 matching lines...) Expand all
1191 int tab_index = -1; 1180 int tab_index = -1;
1192 TabStripModel* tab_strip; 1181 TabStripModel* tab_strip;
1193 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); 1182 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
1194 1183
1195 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function( 1184 scoped_refptr<TabsDuplicateFunction> duplicate_tab_function(
1196 new TabsDuplicateFunction()); 1185 new TabsDuplicateFunction());
1197 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); 1186 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension());
1198 duplicate_tab_function->set_extension(empty_extension.get()); 1187 duplicate_tab_function->set_extension(empty_extension.get());
1199 duplicate_tab_function->set_has_callback(true); 1188 duplicate_tab_function->set_has_callback(true);
1200 1189
1201 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( 1190 std::unique_ptr<base::DictionaryValue> duplicate_result(
1202 utils::RunFunctionAndReturnSingleResult( 1191 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
1203 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), 1192 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id),
1204 browser()))); 1193 browser())));
1205 1194
1206 int duplicate_tab_id = GetTabId(duplicate_result.get()); 1195 int duplicate_tab_id = GetTabId(duplicate_result.get());
1207 int duplicate_tab_window_id = GetTabWindowId(duplicate_result.get()); 1196 int duplicate_tab_window_id = GetTabWindowId(duplicate_result.get());
1208 int duplicate_tab_index = 1197 int duplicate_tab_index =
1209 api_test_utils::GetInteger(duplicate_result.get(), "index"); 1198 api_test_utils::GetInteger(duplicate_result.get(), "index");
1210 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); 1199 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType());
1211 // Duplicate tab id should be different from the original tab id. 1200 // Duplicate tab id should be different from the original tab id.
1212 EXPECT_NE(tab_id, duplicate_tab_id); 1201 EXPECT_NE(tab_id, duplicate_tab_id);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 #if defined(OS_MACOSX) 1275 #if defined(OS_MACOSX)
1287 listener.Reply(""); 1276 listener.Reply("");
1288 #else 1277 #else
1289 listener.Reply("focus"); 1278 listener.Reply("focus");
1290 #endif 1279 #endif
1291 1280
1292 ASSERT_TRUE(catcher.GetNextResult()); 1281 ASSERT_TRUE(catcher.GetNextResult());
1293 } 1282 }
1294 1283
1295 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, ExecuteScriptOnDevTools) { 1284 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, ExecuteScriptOnDevTools) {
1296 scoped_ptr<base::DictionaryValue> test_extension_value( 1285 std::unique_ptr<base::DictionaryValue> test_extension_value(
1297 api_test_utils::ParseDictionary( 1286 api_test_utils::ParseDictionary(
1298 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": " 1287 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": "
1299 "[\"tabs\"]}")); 1288 "[\"tabs\"]}"));
1300 scoped_refptr<Extension> extension( 1289 scoped_refptr<Extension> extension(
1301 api_test_utils::CreateExtension(test_extension_value.get())); 1290 api_test_utils::CreateExtension(test_extension_value.get()));
1302 1291
1303 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync( 1292 DevToolsWindow* devtools = DevToolsWindowTesting::OpenDevToolsWindowSync(
1304 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */); 1293 browser()->tab_strip_model()->GetWebContentsAt(0), false /* is_docked */);
1305 1294
1306 scoped_refptr<TabsExecuteScriptFunction> function = 1295 scoped_refptr<TabsExecuteScriptFunction> function =
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 } 1362 }
1374 1363
1375 testing::AssertionResult ExtensionTabsZoomTest::RunGetZoom( 1364 testing::AssertionResult ExtensionTabsZoomTest::RunGetZoom(
1376 int tab_id, 1365 int tab_id,
1377 double* zoom_factor) { 1366 double* zoom_factor) {
1378 scoped_refptr<TabsGetZoomFunction> get_zoom_function( 1367 scoped_refptr<TabsGetZoomFunction> get_zoom_function(
1379 new TabsGetZoomFunction()); 1368 new TabsGetZoomFunction());
1380 get_zoom_function->set_extension(extension_.get()); 1369 get_zoom_function->set_extension(extension_.get());
1381 get_zoom_function->set_has_callback(true); 1370 get_zoom_function->set_has_callback(true);
1382 1371
1383 scoped_ptr<base::Value> get_zoom_result( 1372 std::unique_ptr<base::Value> get_zoom_result(
1384 utils::RunFunctionAndReturnSingleResult( 1373 utils::RunFunctionAndReturnSingleResult(
1385 get_zoom_function.get(), 1374 get_zoom_function.get(), base::StringPrintf("[%u]", tab_id),
1386 base::StringPrintf("[%u]", tab_id),
1387 browser())); 1375 browser()));
1388 1376
1389 if (!get_zoom_result) 1377 if (!get_zoom_result)
1390 return testing::AssertionFailure() << "no result"; 1378 return testing::AssertionFailure() << "no result";
1391 if (!get_zoom_result->GetAsDouble(zoom_factor)) 1379 if (!get_zoom_result->GetAsDouble(zoom_factor))
1392 return testing::AssertionFailure() << "result was not a double"; 1380 return testing::AssertionFailure() << "result was not a double";
1393 1381
1394 return testing::AssertionSuccess(); 1382 return testing::AssertionSuccess();
1395 } 1383 }
1396 1384
(...skipping 22 matching lines...) Expand all
1419 int tab_id, 1407 int tab_id,
1420 std::string* mode, 1408 std::string* mode,
1421 std::string* scope) { 1409 std::string* scope) {
1422 DCHECK(mode); 1410 DCHECK(mode);
1423 DCHECK(scope); 1411 DCHECK(scope);
1424 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function( 1412 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function(
1425 new TabsGetZoomSettingsFunction()); 1413 new TabsGetZoomSettingsFunction());
1426 get_zoom_settings_function->set_extension(extension_.get()); 1414 get_zoom_settings_function->set_extension(extension_.get());
1427 get_zoom_settings_function->set_has_callback(true); 1415 get_zoom_settings_function->set_has_callback(true);
1428 1416
1429 scoped_ptr<base::DictionaryValue> get_zoom_settings_result( 1417 std::unique_ptr<base::DictionaryValue> get_zoom_settings_result(
1430 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 1418 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
1431 get_zoom_settings_function.get(), 1419 get_zoom_settings_function.get(), base::StringPrintf("[%u]", tab_id),
1432 base::StringPrintf("[%u]", tab_id),
1433 browser()))); 1420 browser())));
1434 1421
1435 if (!get_zoom_settings_result) 1422 if (!get_zoom_settings_result)
1436 return testing::AssertionFailure() << "no result"; 1423 return testing::AssertionFailure() << "no result";
1437 1424
1438 *mode = api_test_utils::GetString(get_zoom_settings_result.get(), "mode"); 1425 *mode = api_test_utils::GetString(get_zoom_settings_result.get(), "mode");
1439 *scope = api_test_utils::GetString(get_zoom_settings_result.get(), "scope"); 1426 *scope = api_test_utils::GetString(get_zoom_settings_result.get(), "scope");
1440 1427
1441 return testing::AssertionSuccess(); 1428 return testing::AssertionSuccess();
1442 } 1429 }
1443 1430
1444 testing::AssertionResult ExtensionTabsZoomTest::RunGetDefaultZoom( 1431 testing::AssertionResult ExtensionTabsZoomTest::RunGetDefaultZoom(
1445 int tab_id, 1432 int tab_id,
1446 double* default_zoom_factor) { 1433 double* default_zoom_factor) {
1447 DCHECK(default_zoom_factor); 1434 DCHECK(default_zoom_factor);
1448 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function( 1435 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function(
1449 new TabsGetZoomSettingsFunction()); 1436 new TabsGetZoomSettingsFunction());
1450 get_zoom_settings_function->set_extension(extension_.get()); 1437 get_zoom_settings_function->set_extension(extension_.get());
1451 get_zoom_settings_function->set_has_callback(true); 1438 get_zoom_settings_function->set_has_callback(true);
1452 1439
1453 scoped_ptr<base::DictionaryValue> get_zoom_settings_result( 1440 std::unique_ptr<base::DictionaryValue> get_zoom_settings_result(
1454 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 1441 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
1455 get_zoom_settings_function.get(), 1442 get_zoom_settings_function.get(), base::StringPrintf("[%u]", tab_id),
1456 base::StringPrintf("[%u]", tab_id),
1457 browser()))); 1443 browser())));
1458 1444
1459 if (!get_zoom_settings_result) 1445 if (!get_zoom_settings_result)
1460 return testing::AssertionFailure() << "no result"; 1446 return testing::AssertionFailure() << "no result";
1461 1447
1462 if (!get_zoom_settings_result->GetDouble("defaultZoomFactor", 1448 if (!get_zoom_settings_result->GetDouble("defaultZoomFactor",
1463 default_zoom_factor)) { 1449 default_zoom_factor)) {
1464 return testing::AssertionFailure() 1450 return testing::AssertionFailure()
1465 << "default zoom factor not found in result"; 1451 << "default zoom factor not found in result";
1466 } 1452 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 EXPECT_TRUE( 1732 EXPECT_TRUE(
1747 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 1733 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
1748 1734
1749 // chrome.tabs.setZoomSettings(). 1735 // chrome.tabs.setZoomSettings().
1750 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); 1736 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab");
1751 EXPECT_TRUE( 1737 EXPECT_TRUE(
1752 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 1738 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
1753 } 1739 }
1754 1740
1755 } // namespace extensions 1741 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_interactive_test.cc ('k') | chrome/browser/extensions/api/tabs/tabs_windows_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698