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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "net/test/spawned_test_server/spawned_test_server.h" | 35 #include "net/test/spawned_test_server/spawned_test_server.h" |
36 #include "ui/gfx/geometry/rect.h" | 36 #include "ui/gfx/geometry/rect.h" |
37 | 37 |
38 namespace extensions { | 38 namespace extensions { |
39 | 39 |
40 namespace keys = tabs_constants; | 40 namespace keys = tabs_constants; |
41 namespace utils = extension_function_test_utils; | 41 namespace utils = extension_function_test_utils; |
42 | 42 |
43 namespace { | 43 namespace { |
44 using ExtensionTabsTest = InProcessBrowserTest; | 44 using ExtensionTabsTest = InProcessBrowserTest; |
45 using ExtensionWindowCreateTest = InProcessBrowserTest; | 45 |
46 } | 46 class ExtensionWindowCreateTest : public InProcessBrowserTest { |
| 47 public: |
| 48 // Runs chrome.windows.create(), expecting an error. |
| 49 std::string RunCreateWindowExpectError(const std::string& args) { |
| 50 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction); |
| 51 function->set_extension(test_util::CreateEmptyExtension().get()); |
| 52 return api_test_utils::RunFunctionAndReturnError(function.get(), args, |
| 53 browser()->profile()); |
| 54 } |
| 55 }; |
| 56 |
| 57 } // namespace |
47 | 58 |
48 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { | 59 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { |
49 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 60 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
50 | 61 |
51 // Invalid window ID error. | 62 // Invalid window ID error. |
52 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); | 63 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); |
53 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 64 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
54 function->set_extension(extension.get()); | 65 function->set_extension(extension.get()); |
55 EXPECT_TRUE(MatchPattern( | 66 EXPECT_TRUE(MatchPattern( |
56 utils::RunFunctionAndReturnError( | 67 utils::RunFunctionAndReturnError( |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 new_window = ExtensionTabUtil::GetBrowserFromWindowID(function.get(), | 598 new_window = ExtensionTabUtil::GetBrowserFromWindowID(function.get(), |
588 window_id, &error); | 599 window_id, &error); |
589 EXPECT_TRUE(error.empty()); | 600 EXPECT_TRUE(error.empty()); |
590 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) | 601 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) |
591 // DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update | 602 // DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update |
592 // from the window server. | 603 // from the window server. |
593 EXPECT_TRUE(new_window->window()->IsMinimized()); | 604 EXPECT_TRUE(new_window->window()->IsMinimized()); |
594 #endif | 605 #endif |
595 } | 606 } |
596 | 607 |
| 608 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) { |
| 609 EXPECT_TRUE( |
| 610 MatchPattern(RunCreateWindowExpectError( |
| 611 "[{\"state\": \"fullscreen\", \"type\": \"panel\"}]"), |
| 612 keys::kInvalidWindowStateError)); |
| 613 EXPECT_TRUE( |
| 614 MatchPattern(RunCreateWindowExpectError( |
| 615 "[{\"state\": \"maximized\", \"type\": \"panel\"}]"), |
| 616 keys::kInvalidWindowStateError)); |
| 617 EXPECT_TRUE( |
| 618 MatchPattern(RunCreateWindowExpectError( |
| 619 "[{\"state\": \"minimized\", \"type\": \"panel\"}]"), |
| 620 keys::kInvalidWindowStateError)); |
| 621 EXPECT_TRUE( |
| 622 MatchPattern(RunCreateWindowExpectError( |
| 623 "[{\"state\": \"minimized\", \"focused\": true}]"), |
| 624 keys::kInvalidWindowStateError)); |
| 625 EXPECT_TRUE( |
| 626 MatchPattern(RunCreateWindowExpectError( |
| 627 "[{\"state\": \"maximized\", \"focused\": false}]"), |
| 628 keys::kInvalidWindowStateError)); |
| 629 EXPECT_TRUE( |
| 630 MatchPattern(RunCreateWindowExpectError( |
| 631 "[{\"state\": \"fullscreen\", \"focused\": false}]"), |
| 632 keys::kInvalidWindowStateError)); |
| 633 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( |
| 634 "[{\"state\": \"minimized\", \"width\": 500}]"), |
| 635 keys::kInvalidWindowStateError)); |
| 636 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( |
| 637 "[{\"state\": \"maximized\", \"width\": 500}]"), |
| 638 keys::kInvalidWindowStateError)); |
| 639 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( |
| 640 "[{\"state\": \"fullscreen\", \"width\": 500}]"), |
| 641 keys::kInvalidWindowStateError)); |
| 642 } |
| 643 |
597 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { | 644 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { |
598 content::OpenURLParams params(GURL(url::kAboutBlankURL), | 645 content::OpenURLParams params(GURL(url::kAboutBlankURL), |
599 content::Referrer(), | 646 content::Referrer(), |
600 NEW_FOREGROUND_TAB, | 647 NEW_FOREGROUND_TAB, |
601 ui::PAGE_TRANSITION_LINK, | 648 ui::PAGE_TRANSITION_LINK, |
602 false); | 649 false); |
603 content::WebContents* web_contents = browser()->OpenURL(params); | 650 content::WebContents* web_contents = browser()->OpenURL(params); |
604 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 651 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
605 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); | 652 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); |
606 int tab_index = -1; | 653 int tab_index = -1; |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 // Test chrome.tabs.setZoom(). | 1162 // Test chrome.tabs.setZoom(). |
1116 error = RunSetZoomExpectError(tab_id, 3.14159); | 1163 error = RunSetZoomExpectError(tab_id, 3.14159); |
1117 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1164 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1118 | 1165 |
1119 // chrome.tabs.setZoomSettings(). | 1166 // chrome.tabs.setZoomSettings(). |
1120 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 1167 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
1121 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1168 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1122 } | 1169 } |
1123 | 1170 |
1124 } // namespace extensions | 1171 } // namespace extensions |
OLD | NEW |