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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 1015123003: Extension window.create API accepts state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
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 38309a6a13404ec1b909ac5565e8a24fb4b30bcc..1ecdf956ac9b30aceaa62cdf991829c281a07acc 100644
--- a/chrome/browser/extensions/api/tabs/tabs_test.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_test.cc
@@ -37,11 +37,40 @@ namespace extensions {
namespace keys = tabs_constants;
namespace utils = extension_function_test_utils;
-namespace {
-
class ExtensionTabsTest : public InProcessBrowserTest {
};
+class ExtensionWindowCreateTest : public InProcessBrowserTest {
+ public:
+ void SetUpOnMainThread() override;
+
+ // Run chrome.windows.create(). If success, return |true|.
+ bool RunCreateWindow(const std::string& args);
+
+ // Runs chrome.windows.create(), expecting an error.
+ std::string RunCreateWindowExpectError(const std::string& args);
+
+ private:
+ scoped_refptr<Extension> extension_;
+};
+
+void ExtensionWindowCreateTest::SetUpOnMainThread() {
+ extension_ = test_util::CreateEmptyExtension();
+}
+
+bool ExtensionWindowCreateTest::RunCreateWindow(const std::string& args) {
+ scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
+ function->set_extension(extension_.get());
+ return extensions::api_test_utils::RunFunction(function.get(), args,
+ browser()->profile());
+}
+
+std::string ExtensionWindowCreateTest::RunCreateWindowExpectError(
+ const std::string& args) {
+ scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
+ function->set_extension(extension_.get());
+ return extensions::api_test_utils::RunFunctionAndReturnError(
+ function.get(), args, browser()->profile());
}
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) {
@@ -561,6 +590,54 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) {
keys::kInvalidWindowStateError));
}
+IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) {
+ EXPECT_TRUE(RunCreateWindow("[{\"state\": \"fullscreen\"}]"));
+ EXPECT_TRUE(RunCreateWindow("[{\"state\": \"maximized\"}]"));
+ EXPECT_TRUE(RunCreateWindow("[{\"state\": \"minimized\"}]"));
+ EXPECT_TRUE(RunCreateWindow("[{\"state\": \"normal\"}]"));
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, InvalidCreateWindowState) {
+ 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(),

Powered by Google App Engine
This is Rietveld 408576698