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 class ExtensionWindowCreateTest : public InProcessBrowserTest { | |
47 public: | |
48 void SetUpOnMainThread() override; | |
49 | |
50 base::Value* RunCreateWindow(const std::string& args); | |
51 | |
52 // Runs chrome.windows.create(), expecting an error. | |
53 std::string RunCreateWindowExpectError(const std::string& args); | |
54 | |
55 WindowsCreateFunction* function(); | |
56 | |
57 private: | |
58 scoped_refptr<Extension> extension_; | |
59 scoped_refptr<WindowsCreateFunction> function_; | |
not at google - send to devlin
2015/04/20 16:32:55
Can you make these tests sateless? I don't know wh
limasdf
2015/04/22 15:49:33
You're exactly right. Done.
| |
60 }; | |
61 | |
62 void ExtensionWindowCreateTest::SetUpOnMainThread() { | |
63 InProcessBrowserTest::SetUpOnMainThread(); | |
64 extension_ = test_util::CreateEmptyExtension(); | |
46 } | 65 } |
47 | 66 |
67 base::Value* ExtensionWindowCreateTest::RunCreateWindow( | |
68 const std::string& args) { | |
69 function_ = new WindowsCreateFunction(); | |
70 function_->set_extension(extension_.get()); | |
71 return api_test_utils::RunFunctionAndReturnSingleResult(function_.get(), args, | |
72 browser()->profile()); | |
73 } | |
74 | |
75 std::string ExtensionWindowCreateTest::RunCreateWindowExpectError( | |
76 const std::string& args) { | |
77 function_ = new WindowsCreateFunction(); | |
78 function_->set_extension(extension_.get()); | |
79 return api_test_utils::RunFunctionAndReturnError(function_.get(), args, | |
80 browser()->profile()); | |
81 } | |
82 | |
83 WindowsCreateFunction* ExtensionWindowCreateTest::function() { | |
84 return function_.get(); | |
85 } | |
86 | |
87 } // namespace | |
88 | |
48 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { | 89 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { |
49 int window_id = ExtensionTabUtil::GetWindowId(browser()); | 90 int window_id = ExtensionTabUtil::GetWindowId(browser()); |
50 | 91 |
51 // Invalid window ID error. | 92 // Invalid window ID error. |
52 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); | 93 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); |
53 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 94 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
54 function->set_extension(extension.get()); | 95 function->set_extension(extension.get()); |
55 EXPECT_TRUE(MatchPattern( | 96 EXPECT_TRUE(MatchPattern( |
56 utils::RunFunctionAndReturnError( | 97 utils::RunFunctionAndReturnError( |
57 function.get(), | 98 function.get(), |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 function->set_extension(extension.get()); | 597 function->set_extension(extension.get()); |
557 EXPECT_TRUE(MatchPattern( | 598 EXPECT_TRUE(MatchPattern( |
558 utils::RunFunctionAndReturnError( | 599 utils::RunFunctionAndReturnError( |
559 function.get(), | 600 function.get(), |
560 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 601 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
561 browser()), | 602 browser()), |
562 keys::kInvalidWindowStateError)); | 603 keys::kInvalidWindowStateError)); |
563 } | 604 } |
564 | 605 |
565 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { | 606 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { |
566 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); | 607 scoped_ptr<base::DictionaryValue> result( |
567 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); | 608 utils::ToDictionary(RunCreateWindow("[{\"state\": \"fullscreen\"}]"))); |
568 function->set_extension(extension.get()); | |
569 | 609 |
570 scoped_ptr<base::DictionaryValue> result( | |
571 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | |
572 function.get(), "[{\"state\": \"fullscreen\"}]", browser(), | |
573 utils::INCLUDE_INCOGNITO))); | |
574 int window_id = api_test_utils::GetInteger(result.get(), "id"); | 610 int window_id = api_test_utils::GetInteger(result.get(), "id"); |
575 std::string error; | 611 std::string error; |
576 Browser* new_window = ExtensionTabUtil::GetBrowserFromWindowID( | 612 Browser* new_window = |
577 function.get(), window_id, &error); | 613 ExtensionTabUtil::GetBrowserFromWindowID(function(), window_id, &error); |
578 EXPECT_TRUE(new_window->window()->IsFullscreen()); | 614 EXPECT_TRUE(new_window->window()->IsFullscreen()); |
579 EXPECT_TRUE(error.empty()); | 615 EXPECT_TRUE(error.empty()); |
580 | 616 |
581 function = new WindowsCreateFunction(); | 617 result.reset( |
582 function->set_extension(extension.get()); | 618 utils::ToDictionary(RunCreateWindow("[{\"state\": \"minimized\"}]"))); |
583 result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( | |
584 function.get(), "[{\"state\": \"minimized\"}]", browser(), | |
585 utils::INCLUDE_INCOGNITO))); | |
586 window_id = api_test_utils::GetInteger(result.get(), "id"); | 619 window_id = api_test_utils::GetInteger(result.get(), "id"); |
587 new_window = ExtensionTabUtil::GetBrowserFromWindowID(function.get(), | 620 new_window = |
588 window_id, &error); | 621 ExtensionTabUtil::GetBrowserFromWindowID(function(), window_id, &error); |
589 EXPECT_TRUE(error.empty()); | 622 EXPECT_TRUE(error.empty()); |
590 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) | 623 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) |
591 // DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update | 624 // DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update |
592 // from the window server. | 625 // from the window server. |
593 EXPECT_TRUE(new_window->window()->IsMinimized()); | 626 EXPECT_TRUE(new_window->window()->IsMinimized()); |
594 #endif | 627 #endif |
595 } | 628 } |
596 | 629 |
630 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) { | |
631 EXPECT_TRUE( | |
632 MatchPattern(RunCreateWindowExpectError( | |
633 "[{\"state\": \"fullscreen\", \"type\": \"panel\"}]"), | |
634 keys::kInvalidWindowStateError)); | |
635 EXPECT_TRUE( | |
636 MatchPattern(RunCreateWindowExpectError( | |
637 "[{\"state\": \"maximized\", \"type\": \"panel\"}]"), | |
638 keys::kInvalidWindowStateError)); | |
639 EXPECT_TRUE( | |
640 MatchPattern(RunCreateWindowExpectError( | |
641 "[{\"state\": \"minimized\", \"type\": \"panel\"}]"), | |
642 keys::kInvalidWindowStateError)); | |
643 EXPECT_TRUE( | |
644 MatchPattern(RunCreateWindowExpectError( | |
645 "[{\"state\": \"minimized\", \"focused\": true}]"), | |
646 keys::kInvalidWindowStateError)); | |
647 EXPECT_TRUE( | |
648 MatchPattern(RunCreateWindowExpectError( | |
649 "[{\"state\": \"maximized\", \"focused\": false}]"), | |
650 keys::kInvalidWindowStateError)); | |
651 EXPECT_TRUE( | |
652 MatchPattern(RunCreateWindowExpectError( | |
653 "[{\"state\": \"fullscreen\", \"focused\": false}]"), | |
654 keys::kInvalidWindowStateError)); | |
655 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( | |
656 "[{\"state\": \"minimized\", \"width\": 500}]"), | |
657 keys::kInvalidWindowStateError)); | |
658 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( | |
659 "[{\"state\": \"maximized\", \"width\": 500}]"), | |
660 keys::kInvalidWindowStateError)); | |
661 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( | |
662 "[{\"state\": \"fullscreen\", \"width\": 500}]"), | |
663 keys::kInvalidWindowStateError)); | |
664 } | |
665 | |
597 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { | 666 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { |
598 content::OpenURLParams params(GURL(url::kAboutBlankURL), | 667 content::OpenURLParams params(GURL(url::kAboutBlankURL), |
599 content::Referrer(), | 668 content::Referrer(), |
600 NEW_FOREGROUND_TAB, | 669 NEW_FOREGROUND_TAB, |
601 ui::PAGE_TRANSITION_LINK, | 670 ui::PAGE_TRANSITION_LINK, |
602 false); | 671 false); |
603 content::WebContents* web_contents = browser()->OpenURL(params); | 672 content::WebContents* web_contents = browser()->OpenURL(params); |
604 int tab_id = ExtensionTabUtil::GetTabId(web_contents); | 673 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
605 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); | 674 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); |
606 int tab_index = -1; | 675 int tab_index = -1; |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1115 // Test chrome.tabs.setZoom(). | 1184 // Test chrome.tabs.setZoom(). |
1116 error = RunSetZoomExpectError(tab_id, 3.14159); | 1185 error = RunSetZoomExpectError(tab_id, 3.14159); |
1117 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1186 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1118 | 1187 |
1119 // chrome.tabs.setZoomSettings(). | 1188 // chrome.tabs.setZoomSettings(). |
1120 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); | 1189 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); |
1121 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); | 1190 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); |
1122 } | 1191 } |
1123 | 1192 |
1124 } // namespace extensions | 1193 } // namespace extensions |
OLD | NEW |