OLD | NEW |
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" |
| 11 #include "base/strings/pattern.h" |
| 12 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "chrome/browser/devtools/devtools_window_testing.h" | 16 #include "chrome/browser/devtools/devtools_window_testing.h" |
15 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 17 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 18 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
17 #include "chrome/browser/extensions/extension_function_test_utils.h" | 19 #include "chrome/browser/extensions/extension_function_test_utils.h" |
18 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
19 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 58 |
57 } // namespace | 59 } // namespace |
58 | 60 |
59 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { | 61 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { |
60 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 62 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
61 | 63 |
62 // Invalid window ID error. | 64 // Invalid window ID error. |
63 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); | 65 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); |
64 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 66 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
65 function->set_extension(extension.get()); | 67 function->set_extension(extension.get()); |
66 EXPECT_TRUE(MatchPattern( | 68 EXPECT_TRUE(base::MatchPattern( |
67 utils::RunFunctionAndReturnError( | 69 utils::RunFunctionAndReturnError( |
68 function.get(), | 70 function.get(), base::StringPrintf("[%u]", window_id + 1), browser()), |
69 base::StringPrintf("[%u]", window_id + 1), | |
70 browser()), | |
71 keys::kWindowNotFoundError)); | 71 keys::kWindowNotFoundError)); |
72 | 72 |
73 // Basic window details. | 73 // Basic window details. |
74 gfx::Rect bounds; | 74 gfx::Rect bounds; |
75 if (browser()->window()->IsMinimized()) | 75 if (browser()->window()->IsMinimized()) |
76 bounds = browser()->window()->GetRestoredBounds(); | 76 bounds = browser()->window()->GetRestoredBounds(); |
77 else | 77 else |
78 bounds = browser()->window()->GetBounds(); | 78 bounds = browser()->window()->GetBounds(); |
79 | 79 |
80 function = new WindowsGetFunction(); | 80 function = new WindowsGetFunction(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 browser()))); | 130 browser()))); |
131 EXPECT_EQ("popup", api_test_utils::GetString(result.get(), "type")); | 131 EXPECT_EQ("popup", api_test_utils::GetString(result.get(), "type")); |
132 | 132 |
133 // Incognito. | 133 // Incognito. |
134 Browser* incognito_browser = CreateIncognitoBrowser(); | 134 Browser* incognito_browser = CreateIncognitoBrowser(); |
135 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser); | 135 int incognito_window_id = ExtensionTabUtil::GetWindowId(incognito_browser); |
136 | 136 |
137 // Without "include_incognito". | 137 // Without "include_incognito". |
138 function = new WindowsGetFunction(); | 138 function = new WindowsGetFunction(); |
139 function->set_extension(extension.get()); | 139 function->set_extension(extension.get()); |
140 EXPECT_TRUE(MatchPattern( | 140 EXPECT_TRUE(base::MatchPattern( |
141 utils::RunFunctionAndReturnError( | 141 utils::RunFunctionAndReturnError( |
142 function.get(), | 142 function.get(), base::StringPrintf("[%u]", incognito_window_id), |
143 base::StringPrintf("[%u]", incognito_window_id), | |
144 browser()), | 143 browser()), |
145 keys::kWindowNotFoundError)); | 144 keys::kWindowNotFoundError)); |
146 | 145 |
147 // With "include_incognito". | 146 // With "include_incognito". |
148 function = new WindowsGetFunction(); | 147 function = new WindowsGetFunction(); |
149 function->set_extension(extension.get()); | 148 function->set_extension(extension.get()); |
150 result.reset(utils::ToDictionary( | 149 result.reset(utils::ToDictionary( |
151 utils::RunFunctionAndReturnSingleResult( | 150 utils::RunFunctionAndReturnSingleResult( |
152 function.get(), | 151 function.get(), |
153 base::StringPrintf("[%u]", incognito_window_id), | 152 base::StringPrintf("[%u]", incognito_window_id), |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 static const char kArgsWithExplicitIncognitoParam[] = | 359 static const char kArgsWithExplicitIncognitoParam[] = |
361 "[{\"url\": \"about:blank\", \"incognito\": false }]"; | 360 "[{\"url\": \"about:blank\", \"incognito\": false }]"; |
362 // Force Incognito mode. | 361 // Force Incognito mode. |
363 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 362 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
364 IncognitoModePrefs::FORCED); | 363 IncognitoModePrefs::FORCED); |
365 | 364 |
366 // Run with an explicit "incognito" param. | 365 // Run with an explicit "incognito" param. |
367 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); | 366 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); |
368 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 367 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
369 function->set_extension(extension.get()); | 368 function->set_extension(extension.get()); |
370 EXPECT_TRUE(MatchPattern( | 369 EXPECT_TRUE(base::MatchPattern( |
371 utils::RunFunctionAndReturnError(function.get(), | 370 utils::RunFunctionAndReturnError( |
372 kArgsWithExplicitIncognitoParam, | 371 function.get(), kArgsWithExplicitIncognitoParam, browser()), |
373 browser()), | |
374 keys::kIncognitoModeIsForced)); | 372 keys::kIncognitoModeIsForced)); |
375 | 373 |
376 // Now try opening a normal window from incognito window. | 374 // Now try opening a normal window from incognito window. |
377 Browser* incognito_browser = CreateIncognitoBrowser(); | 375 Browser* incognito_browser = CreateIncognitoBrowser(); |
378 // Run with an explicit "incognito" param. | 376 // Run with an explicit "incognito" param. |
379 function = new WindowsCreateFunction(); | 377 function = new WindowsCreateFunction(); |
380 function->set_extension(extension.get()); | 378 function->set_extension(extension.get()); |
381 EXPECT_TRUE(MatchPattern( | 379 EXPECT_TRUE(base::MatchPattern( |
382 utils::RunFunctionAndReturnError(function.get(), | 380 utils::RunFunctionAndReturnError( |
383 kArgsWithExplicitIncognitoParam, | 381 function.get(), kArgsWithExplicitIncognitoParam, incognito_browser), |
384 incognito_browser), | |
385 keys::kIncognitoModeIsForced)); | 382 keys::kIncognitoModeIsForced)); |
386 } | 383 } |
387 | 384 |
388 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, | 385 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, |
389 DontCreateIncognitoWindowWhenIncognitoDisabled) { | 386 DontCreateIncognitoWindowWhenIncognitoDisabled) { |
390 static const char kArgs[] = | 387 static const char kArgs[] = |
391 "[{\"url\": \"about:blank\", \"incognito\": true }]"; | 388 "[{\"url\": \"about:blank\", \"incognito\": true }]"; |
392 | 389 |
393 Browser* incognito_browser = CreateIncognitoBrowser(); | 390 Browser* incognito_browser = CreateIncognitoBrowser(); |
394 // Disable Incognito mode. | 391 // Disable Incognito mode. |
395 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), | 392 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
396 IncognitoModePrefs::DISABLED); | 393 IncognitoModePrefs::DISABLED); |
397 // Run in normal window. | 394 // Run in normal window. |
398 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); | 395 scoped_refptr<WindowsCreateFunction> function = new WindowsCreateFunction(); |
399 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 396 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
400 function->set_extension(extension.get()); | 397 function->set_extension(extension.get()); |
401 EXPECT_TRUE(MatchPattern( | 398 EXPECT_TRUE(base::MatchPattern( |
402 utils::RunFunctionAndReturnError(function.get(), | 399 utils::RunFunctionAndReturnError(function.get(), kArgs, browser()), |
403 kArgs, | |
404 browser()), | |
405 keys::kIncognitoModeIsDisabled)); | 400 keys::kIncognitoModeIsDisabled)); |
406 | 401 |
407 // Run in incognito window. | 402 // Run in incognito window. |
408 function = new WindowsCreateFunction(); | 403 function = new WindowsCreateFunction(); |
409 function->set_extension(extension.get()); | 404 function->set_extension(extension.get()); |
410 EXPECT_TRUE(MatchPattern( | 405 EXPECT_TRUE(base::MatchPattern(utils::RunFunctionAndReturnError( |
411 utils::RunFunctionAndReturnError(function.get(), | 406 function.get(), kArgs, incognito_browser), |
412 kArgs, | 407 keys::kIncognitoModeIsDisabled)); |
413 incognito_browser), | |
414 keys::kIncognitoModeIsDisabled)); | |
415 } | 408 } |
416 | 409 |
417 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { | 410 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, QueryCurrentWindowTabs) { |
418 const size_t kExtraWindows = 3; | 411 const size_t kExtraWindows = 3; |
419 for (size_t i = 0; i < kExtraWindows; ++i) | 412 for (size_t i = 0; i < kExtraWindows; ++i) |
420 CreateBrowser(browser()->profile()); | 413 CreateBrowser(browser()->profile()); |
421 | 414 |
422 GURL url(url::kAboutBlankURL); | 415 GURL url(url::kAboutBlankURL); |
423 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_LINK); | 416 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_LINK); |
424 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 417 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 518 } |
526 | 519 |
527 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { | 520 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { |
528 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 521 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
529 | 522 |
530 static const char kArgsMinimizedWithFocus[] = | 523 static const char kArgsMinimizedWithFocus[] = |
531 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; | 524 "[%u, {\"state\": \"minimized\", \"focused\": true}]"; |
532 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction(); | 525 scoped_refptr<WindowsUpdateFunction> function = new WindowsUpdateFunction(); |
533 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 526 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
534 function->set_extension(extension.get()); | 527 function->set_extension(extension.get()); |
535 EXPECT_TRUE(MatchPattern( | 528 EXPECT_TRUE(base::MatchPattern( |
536 utils::RunFunctionAndReturnError( | 529 utils::RunFunctionAndReturnError( |
537 function.get(), | 530 function.get(), |
538 base::StringPrintf(kArgsMinimizedWithFocus, window_id), | 531 base::StringPrintf(kArgsMinimizedWithFocus, window_id), browser()), |
539 browser()), | |
540 keys::kInvalidWindowStateError)); | 532 keys::kInvalidWindowStateError)); |
541 | 533 |
542 static const char kArgsMaximizedWithoutFocus[] = | 534 static const char kArgsMaximizedWithoutFocus[] = |
543 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; | 535 "[%u, {\"state\": \"maximized\", \"focused\": false}]"; |
544 function = new WindowsUpdateFunction(); | 536 function = new WindowsUpdateFunction(); |
545 function->set_extension(extension.get()); | 537 function->set_extension(extension.get()); |
546 EXPECT_TRUE(MatchPattern( | 538 EXPECT_TRUE(base::MatchPattern( |
547 utils::RunFunctionAndReturnError( | 539 utils::RunFunctionAndReturnError( |
548 function.get(), | 540 function.get(), |
549 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id), | 541 base::StringPrintf(kArgsMaximizedWithoutFocus, window_id), browser()), |
550 browser()), | |
551 keys::kInvalidWindowStateError)); | 542 keys::kInvalidWindowStateError)); |
552 | 543 |
553 static const char kArgsMinimizedWithBounds[] = | 544 static const char kArgsMinimizedWithBounds[] = |
554 "[%u, {\"state\": \"minimized\", \"width\": 500}]"; | 545 "[%u, {\"state\": \"minimized\", \"width\": 500}]"; |
555 function = new WindowsUpdateFunction(); | 546 function = new WindowsUpdateFunction(); |
556 function->set_extension(extension.get()); | 547 function->set_extension(extension.get()); |
557 EXPECT_TRUE(MatchPattern( | 548 EXPECT_TRUE(base::MatchPattern( |
558 utils::RunFunctionAndReturnError( | 549 utils::RunFunctionAndReturnError( |
559 function.get(), | 550 function.get(), |
560 base::StringPrintf(kArgsMinimizedWithBounds, window_id), | 551 base::StringPrintf(kArgsMinimizedWithBounds, window_id), browser()), |
561 browser()), | |
562 keys::kInvalidWindowStateError)); | 552 keys::kInvalidWindowStateError)); |
563 | 553 |
564 static const char kArgsMaximizedWithBounds[] = | 554 static const char kArgsMaximizedWithBounds[] = |
565 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; | 555 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; |
566 function = new WindowsUpdateFunction(); | 556 function = new WindowsUpdateFunction(); |
567 function->set_extension(extension.get()); | 557 function->set_extension(extension.get()); |
568 EXPECT_TRUE(MatchPattern( | 558 EXPECT_TRUE(base::MatchPattern( |
569 utils::RunFunctionAndReturnError( | 559 utils::RunFunctionAndReturnError( |
570 function.get(), | 560 function.get(), |
571 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 561 base::StringPrintf(kArgsMaximizedWithBounds, window_id), browser()), |
572 browser()), | |
573 keys::kInvalidWindowStateError)); | 562 keys::kInvalidWindowStateError)); |
574 } | 563 } |
575 | 564 |
576 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { | 565 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { |
577 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); | 566 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); |
578 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 567 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
579 function->set_extension(extension.get()); | 568 function->set_extension(extension.get()); |
580 | 569 |
581 scoped_ptr<base::DictionaryValue> result( | 570 scoped_ptr<base::DictionaryValue> result( |
582 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | 571 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( |
(...skipping 19 matching lines...) Expand all Loading... |
602 utils::INCLUDE_INCOGNITO))); | 591 utils::INCLUDE_INCOGNITO))); |
603 window_id = api_test_utils::GetInteger(result.get(), "id"); | 592 window_id = api_test_utils::GetInteger(result.get(), "id"); |
604 new_window = ExtensionTabUtil::GetBrowserFromWindowID(function.get(), | 593 new_window = ExtensionTabUtil::GetBrowserFromWindowID(function.get(), |
605 window_id, &error); | 594 window_id, &error); |
606 EXPECT_TRUE(error.empty()); | 595 EXPECT_TRUE(error.empty()); |
607 EXPECT_TRUE(new_window->window()->IsFullscreen()); | 596 EXPECT_TRUE(new_window->window()->IsFullscreen()); |
608 #endif // !defined(OS_MACOSX) | 597 #endif // !defined(OS_MACOSX) |
609 } | 598 } |
610 | 599 |
611 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) { | 600 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) { |
| 601 EXPECT_TRUE(base::MatchPattern( |
| 602 RunCreateWindowExpectError( |
| 603 "[{\"state\": \"fullscreen\", \"type\": \"panel\"}]"), |
| 604 keys::kInvalidWindowStateError)); |
| 605 EXPECT_TRUE(base::MatchPattern( |
| 606 RunCreateWindowExpectError( |
| 607 "[{\"state\": \"maximized\", \"type\": \"panel\"}]"), |
| 608 keys::kInvalidWindowStateError)); |
| 609 EXPECT_TRUE(base::MatchPattern( |
| 610 RunCreateWindowExpectError( |
| 611 "[{\"state\": \"minimized\", \"type\": \"panel\"}]"), |
| 612 keys::kInvalidWindowStateError)); |
612 EXPECT_TRUE( | 613 EXPECT_TRUE( |
613 MatchPattern(RunCreateWindowExpectError( | 614 base::MatchPattern(RunCreateWindowExpectError( |
614 "[{\"state\": \"fullscreen\", \"type\": \"panel\"}]"), | 615 "[{\"state\": \"minimized\", \"focused\": true}]"), |
615 keys::kInvalidWindowStateError)); | 616 keys::kInvalidWindowStateError)); |
| 617 EXPECT_TRUE(base::MatchPattern( |
| 618 RunCreateWindowExpectError( |
| 619 "[{\"state\": \"maximized\", \"focused\": false}]"), |
| 620 keys::kInvalidWindowStateError)); |
| 621 EXPECT_TRUE(base::MatchPattern( |
| 622 RunCreateWindowExpectError( |
| 623 "[{\"state\": \"fullscreen\", \"focused\": false}]"), |
| 624 keys::kInvalidWindowStateError)); |
616 EXPECT_TRUE( | 625 EXPECT_TRUE( |
617 MatchPattern(RunCreateWindowExpectError( | 626 base::MatchPattern(RunCreateWindowExpectError( |
618 "[{\"state\": \"maximized\", \"type\": \"panel\"}]"), | 627 "[{\"state\": \"minimized\", \"width\": 500}]"), |
619 keys::kInvalidWindowStateError)); | 628 keys::kInvalidWindowStateError)); |
620 EXPECT_TRUE( | 629 EXPECT_TRUE( |
621 MatchPattern(RunCreateWindowExpectError( | 630 base::MatchPattern(RunCreateWindowExpectError( |
622 "[{\"state\": \"minimized\", \"type\": \"panel\"}]"), | 631 "[{\"state\": \"maximized\", \"width\": 500}]"), |
623 keys::kInvalidWindowStateError)); | 632 keys::kInvalidWindowStateError)); |
624 EXPECT_TRUE( | 633 EXPECT_TRUE( |
625 MatchPattern(RunCreateWindowExpectError( | 634 base::MatchPattern(RunCreateWindowExpectError( |
626 "[{\"state\": \"minimized\", \"focused\": true}]"), | 635 "[{\"state\": \"fullscreen\", \"width\": 500}]"), |
627 keys::kInvalidWindowStateError)); | 636 keys::kInvalidWindowStateError)); |
628 EXPECT_TRUE( | |
629 MatchPattern(RunCreateWindowExpectError( | |
630 "[{\"state\": \"maximized\", \"focused\": false}]"), | |
631 keys::kInvalidWindowStateError)); | |
632 EXPECT_TRUE( | |
633 MatchPattern(RunCreateWindowExpectError( | |
634 "[{\"state\": \"fullscreen\", \"focused\": false}]"), | |
635 keys::kInvalidWindowStateError)); | |
636 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( | |
637 "[{\"state\": \"minimized\", \"width\": 500}]"), | |
638 keys::kInvalidWindowStateError)); | |
639 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( | |
640 "[{\"state\": \"maximized\", \"width\": 500}]"), | |
641 keys::kInvalidWindowStateError)); | |
642 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( | |
643 "[{\"state\": \"fullscreen\", \"width\": 500}]"), | |
644 keys::kInvalidWindowStateError)); | |
645 } | 637 } |
646 | 638 |
647 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { | 639 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { |
648 content::OpenURLParams params(GURL(url::kAboutBlankURL), | 640 content::OpenURLParams params(GURL(url::kAboutBlankURL), |
649 content::Referrer(), | 641 content::Referrer(), |
650 NEW_FOREGROUND_TAB, | 642 NEW_FOREGROUND_TAB, |
651 ui::PAGE_TRANSITION_LINK, | 643 ui::PAGE_TRANSITION_LINK, |
652 false); | 644 false); |
653 content::WebContents* web_contents = browser()->OpenURL(params); | 645 content::WebContents* web_contents = browser()->OpenURL(params); |
654 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 646 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 EXPECT_TRUE(RunSetZoomSettings(tab_id_A1, "manual", NULL)); | 1065 EXPECT_TRUE(RunSetZoomSettings(tab_id_A1, "manual", NULL)); |
1074 EXPECT_TRUE(RunSetZoom(tab_id_A1, 1.3f)); | 1066 EXPECT_TRUE(RunSetZoom(tab_id_A1, 1.3f)); |
1075 EXPECT_FLOAT_EQ( | 1067 EXPECT_FLOAT_EQ( |
1076 1.3f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A1))); | 1068 1.3f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A1))); |
1077 EXPECT_FLOAT_EQ( | 1069 EXPECT_FLOAT_EQ( |
1078 1.1f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A2))); | 1070 1.1f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A2))); |
1079 | 1071 |
1080 // Test 'disabled' mode, which will reset A1's zoom to 1.f. | 1072 // Test 'disabled' mode, which will reset A1's zoom to 1.f. |
1081 EXPECT_TRUE(RunSetZoomSettings(tab_id_A1, "disabled", NULL)); | 1073 EXPECT_TRUE(RunSetZoomSettings(tab_id_A1, "disabled", NULL)); |
1082 std::string error = RunSetZoomExpectError(tab_id_A1, 1.4f); | 1074 std::string error = RunSetZoomExpectError(tab_id_A1, 1.4f); |
1083 EXPECT_TRUE(MatchPattern(error, keys::kCannotZoomDisabledTabError)); | 1075 EXPECT_TRUE(base::MatchPattern(error, keys::kCannotZoomDisabledTabError)); |
1084 EXPECT_FLOAT_EQ( | 1076 EXPECT_FLOAT_EQ( |
1085 1.f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A1))); | 1077 1.f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A1))); |
1086 // We should still be able to zoom A2 though. | 1078 // We should still be able to zoom A2 though. |
1087 EXPECT_TRUE(RunSetZoom(tab_id_A2, 1.4f)); | 1079 EXPECT_TRUE(RunSetZoom(tab_id_A2, 1.4f)); |
1088 EXPECT_FLOAT_EQ( | 1080 EXPECT_FLOAT_EQ( |
1089 1.4f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A2))); | 1081 1.4f, content::ZoomLevelToZoomFactor(GetZoomLevel(web_contents_A2))); |
1090 } | 1082 } |
1091 | 1083 |
1092 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, PerTabResetsOnNavigation) { | 1084 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, PerTabResetsOnNavigation) { |
1093 net::SpawnedTestServer http_server( | 1085 net::SpawnedTestServer http_server( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 EXPECT_EQ("per-origin", scope); | 1122 EXPECT_EQ("per-origin", scope); |
1131 | 1123 |
1132 EXPECT_TRUE(RunSetZoomSettings(tab_id, "automatic", "per-tab")); | 1124 EXPECT_TRUE(RunSetZoomSettings(tab_id, "automatic", "per-tab")); |
1133 EXPECT_TRUE(RunGetZoomSettings(tab_id, &mode, &scope)); | 1125 EXPECT_TRUE(RunGetZoomSettings(tab_id, &mode, &scope)); |
1134 | 1126 |
1135 EXPECT_EQ("automatic", mode); | 1127 EXPECT_EQ("automatic", mode); |
1136 EXPECT_EQ("per-tab", scope); | 1128 EXPECT_EQ("per-tab", scope); |
1137 | 1129 |
1138 std::string error = | 1130 std::string error = |
1139 RunSetZoomSettingsExpectError(tab_id, "manual", "per-origin"); | 1131 RunSetZoomSettingsExpectError(tab_id, "manual", "per-origin"); |
1140 EXPECT_TRUE(MatchPattern(error, | 1132 EXPECT_TRUE(base::MatchPattern(error, keys::kPerOriginOnlyInAutomaticError)); |
1141 keys::kPerOriginOnlyInAutomaticError)); | |
1142 error = | 1133 error = |
1143 RunSetZoomSettingsExpectError(tab_id, "disabled", "per-origin"); | 1134 RunSetZoomSettingsExpectError(tab_id, "disabled", "per-origin"); |
1144 EXPECT_TRUE(MatchPattern(error, | 1135 EXPECT_TRUE(base::MatchPattern(error, keys::kPerOriginOnlyInAutomaticError)); |
1145 keys::kPerOriginOnlyInAutomaticError)); | |
1146 } | 1136 } |
1147 | 1137 |
1148 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, CannotZoomInvalidTab) { | 1138 IN_PROC_BROWSER_TEST_F(ExtensionTabsZoomTest, CannotZoomInvalidTab) { |
1149 content::OpenURLParams params(GetOpenParams(url::kAboutBlankURL)); | 1139 content::OpenURLParams params(GetOpenParams(url::kAboutBlankURL)); |
1150 content::WebContents* web_contents = OpenUrlAndWaitForLoad(params.url); | 1140 content::WebContents* web_contents = OpenUrlAndWaitForLoad(params.url); |
1151 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 1141 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
1152 | 1142 |
1153 int bogus_id = tab_id + 100; | 1143 int bogus_id = tab_id + 100; |
1154 std::string error = RunSetZoomExpectError(bogus_id, 3.14159); | 1144 std::string error = RunSetZoomExpectError(bogus_id, 3.14159); |
1155 EXPECT_TRUE(MatchPattern(error, keys::kTabNotFoundError)); | 1145 EXPECT_TRUE(base::MatchPattern(error, keys::kTabNotFoundError)); |
1156 | 1146 |
1157 error = RunSetZoomSettingsExpectError(bogus_id, "manual", "per-tab"); | 1147 error = RunSetZoomSettingsExpectError(bogus_id, "manual", "per-tab"); |
1158 EXPECT_TRUE(MatchPattern(error, keys::kTabNotFoundError)); | 1148 EXPECT_TRUE(base::MatchPattern(error, keys::kTabNotFoundError)); |
1159 | 1149 |
1160 const char kNewTestTabArgs[] = "chrome://version"; | 1150 const char kNewTestTabArgs[] = "chrome://version"; |
1161 params = GetOpenParams(kNewTestTabArgs); | 1151 params = GetOpenParams(kNewTestTabArgs); |
1162 web_contents = browser()->OpenURL(params); | 1152 web_contents = browser()->OpenURL(params); |
1163 tab_id = ExtensionTabUtil::GetTabId(web_contents); | 1153 tab_id = ExtensionTabUtil::GetTabId(web_contents); |
1164 | 1154 |
1165 // Test chrome.tabs.setZoom(). | 1155 // Test chrome.tabs.setZoom(). |
1166 error = RunSetZoomExpectError(tab_id, 3.14159); | 1156 error = RunSetZoomExpectError(tab_id, 3.14159); |
1167 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1157 EXPECT_TRUE( |
| 1158 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1168 | 1159 |
1169 // chrome.tabs.setZoomSettings(). | 1160 // chrome.tabs.setZoomSettings(). |
1170 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 1161 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
1171 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1162 EXPECT_TRUE( |
| 1163 base::MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1172 } | 1164 } |
1173 | 1165 |
1174 } // namespace extensions | 1166 } // namespace extensions |
OLD | NEW |