Index: chrome/browser/extensions/api/tabs/tabs_test.cc |
diff --git a/chrome/browser/extensions/api/tabs/tabs_test.cc b/chrome/browser/extensions/api/tabs/tabs_test.cc |
index b606a0accdbff1fe1082c979db0d2d1e5b6ad97a..eeeb6355504d9c57998d4c691365d400b66bcc4f 100644 |
--- a/chrome/browser/extensions/api/tabs/tabs_test.cc |
+++ b/chrome/browser/extensions/api/tabs/tabs_test.cc |
@@ -42,9 +42,50 @@ namespace utils = extension_function_test_utils; |
namespace { |
using ExtensionTabsTest = InProcessBrowserTest; |
-using ExtensionWindowCreateTest = InProcessBrowserTest; |
+ |
+class ExtensionWindowCreateTest : public InProcessBrowserTest { |
+ public: |
+ void SetUpOnMainThread() override; |
+ |
+ base::Value* RunCreateWindow(const std::string& args); |
+ |
+ // Runs chrome.windows.create(), expecting an error. |
+ std::string RunCreateWindowExpectError(const std::string& args); |
+ |
+ WindowsCreateFunction* function(); |
+ |
+ private: |
+ scoped_refptr<Extension> extension_; |
+ 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.
|
+}; |
+ |
+void ExtensionWindowCreateTest::SetUpOnMainThread() { |
+ InProcessBrowserTest::SetUpOnMainThread(); |
+ extension_ = test_util::CreateEmptyExtension(); |
+} |
+ |
+base::Value* ExtensionWindowCreateTest::RunCreateWindow( |
+ const std::string& args) { |
+ function_ = new WindowsCreateFunction(); |
+ function_->set_extension(extension_.get()); |
+ return api_test_utils::RunFunctionAndReturnSingleResult(function_.get(), args, |
+ browser()->profile()); |
+} |
+ |
+std::string ExtensionWindowCreateTest::RunCreateWindowExpectError( |
+ const std::string& args) { |
+ function_ = new WindowsCreateFunction(); |
+ function_->set_extension(extension_.get()); |
+ return api_test_utils::RunFunctionAndReturnError(function_.get(), args, |
+ browser()->profile()); |
} |
+WindowsCreateFunction* ExtensionWindowCreateTest::function() { |
+ return function_.get(); |
+} |
+ |
+} // namespace |
+ |
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { |
int window_id = ExtensionTabUtil::GetWindowId(browser()); |
@@ -563,29 +604,21 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { |
} |
IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { |
- scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction()); |
- scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); |
- function->set_extension(extension.get()); |
- |
scoped_ptr<base::DictionaryValue> result( |
- utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( |
- function.get(), "[{\"state\": \"fullscreen\"}]", browser(), |
- utils::INCLUDE_INCOGNITO))); |
+ utils::ToDictionary(RunCreateWindow("[{\"state\": \"fullscreen\"}]"))); |
+ |
int window_id = api_test_utils::GetInteger(result.get(), "id"); |
std::string error; |
- Browser* new_window = ExtensionTabUtil::GetBrowserFromWindowID( |
- function.get(), window_id, &error); |
+ Browser* new_window = |
+ ExtensionTabUtil::GetBrowserFromWindowID(function(), window_id, &error); |
EXPECT_TRUE(new_window->window()->IsFullscreen()); |
EXPECT_TRUE(error.empty()); |
- function = new WindowsCreateFunction(); |
- function->set_extension(extension.get()); |
- result.reset(utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( |
- function.get(), "[{\"state\": \"minimized\"}]", browser(), |
- utils::INCLUDE_INCOGNITO))); |
+ result.reset( |
+ utils::ToDictionary(RunCreateWindow("[{\"state\": \"minimized\"}]"))); |
window_id = api_test_utils::GetInteger(result.get(), "id"); |
- new_window = ExtensionTabUtil::GetBrowserFromWindowID(function.get(), |
- window_id, &error); |
+ new_window = |
+ ExtensionTabUtil::GetBrowserFromWindowID(function(), window_id, &error); |
EXPECT_TRUE(error.empty()); |
#if !defined(OS_LINUX) || defined(OS_CHROMEOS) |
// DesktopWindowTreeHostX11::IsMinimized() relies on an asynchronous update |
@@ -594,6 +627,42 @@ IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, AcceptState) { |
#endif |
} |
+IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) { |
+ EXPECT_TRUE( |
+ MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"fullscreen\", \"type\": \"panel\"}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE( |
+ MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"maximized\", \"type\": \"panel\"}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE( |
+ MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"minimized\", \"type\": \"panel\"}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE( |
+ MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"minimized\", \"focused\": true}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE( |
+ MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"maximized\", \"focused\": false}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE( |
+ MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"fullscreen\", \"focused\": false}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"minimized\", \"width\": 500}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"maximized\", \"width\": 500}]"), |
+ keys::kInvalidWindowStateError)); |
+ EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError( |
+ "[{\"state\": \"fullscreen\", \"width\": 500}]"), |
+ keys::kInvalidWindowStateError)); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { |
content::OpenURLParams params(GURL(url::kAboutBlankURL), |
content::Referrer(), |