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

Side by Side 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 unified diff | Download patch
OLDNEW
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 19 matching lines...) Expand all
30 #include "extensions/common/manifest_constants.h" 30 #include "extensions/common/manifest_constants.h"
31 #include "extensions/common/test_util.h" 31 #include "extensions/common/test_util.h"
32 #include "net/test/spawned_test_server/spawned_test_server.h" 32 #include "net/test/spawned_test_server/spawned_test_server.h"
33 #include "ui/gfx/geometry/rect.h" 33 #include "ui/gfx/geometry/rect.h"
34 34
35 namespace extensions { 35 namespace extensions {
36 36
37 namespace keys = tabs_constants; 37 namespace keys = tabs_constants;
38 namespace utils = extension_function_test_utils; 38 namespace utils = extension_function_test_utils;
39 39
40 namespace {
41
42 class ExtensionTabsTest : public InProcessBrowserTest { 40 class ExtensionTabsTest : public InProcessBrowserTest {
43 }; 41 };
44 42
43 class ExtensionWindowCreateTest : public InProcessBrowserTest {
44 public:
45 void SetUpOnMainThread() override;
46
47 // Run chrome.windows.create(). If success, return |true|.
48 bool RunCreateWindow(const std::string& args);
49
50 // Runs chrome.windows.create(), expecting an error.
51 std::string RunCreateWindowExpectError(const std::string& args);
52
53 private:
54 scoped_refptr<Extension> extension_;
55 };
56
57 void ExtensionWindowCreateTest::SetUpOnMainThread() {
58 extension_ = test_util::CreateEmptyExtension();
59 }
60
61 bool ExtensionWindowCreateTest::RunCreateWindow(const std::string& args) {
62 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
63 function->set_extension(extension_.get());
64 return extensions::api_test_utils::RunFunction(function.get(), args,
65 browser()->profile());
66 }
67
68 std::string ExtensionWindowCreateTest::RunCreateWindowExpectError(
69 const std::string& args) {
70 scoped_refptr<WindowsCreateFunction> function(new WindowsCreateFunction());
71 function->set_extension(extension_.get());
72 return extensions::api_test_utils::RunFunctionAndReturnError(
73 function.get(), args, browser()->profile());
45 } 74 }
46 75
47 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) { 76 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) {
48 int window_id = ExtensionTabUtil::GetWindowId(browser()); 77 int window_id = ExtensionTabUtil::GetWindowId(browser());
49 78
50 // Invalid window ID error. 79 // Invalid window ID error.
51 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); 80 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction();
52 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension()); 81 scoped_refptr<Extension> extension(test_util::CreateEmptyExtension());
53 function->set_extension(extension.get()); 82 function->set_extension(extension.get());
54 EXPECT_TRUE(MatchPattern( 83 EXPECT_TRUE(MatchPattern(
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 function = new WindowsUpdateFunction(); 583 function = new WindowsUpdateFunction();
555 function->set_extension(extension.get()); 584 function->set_extension(extension.get());
556 EXPECT_TRUE(MatchPattern( 585 EXPECT_TRUE(MatchPattern(
557 utils::RunFunctionAndReturnError( 586 utils::RunFunctionAndReturnError(
558 function.get(), 587 function.get(),
559 base::StringPrintf(kArgsMaximizedWithBounds, window_id), 588 base::StringPrintf(kArgsMaximizedWithBounds, window_id),
560 browser()), 589 browser()),
561 keys::kInvalidWindowStateError)); 590 keys::kInvalidWindowStateError));
562 } 591 }
563 592
593 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, ValidateCreateWindowState) {
594 EXPECT_TRUE(RunCreateWindow("[{\"state\": \"fullscreen\"}]"));
595 EXPECT_TRUE(RunCreateWindow("[{\"state\": \"maximized\"}]"));
596 EXPECT_TRUE(RunCreateWindow("[{\"state\": \"minimized\"}]"));
597 EXPECT_TRUE(RunCreateWindow("[{\"state\": \"normal\"}]"));
598 }
599
600 IN_PROC_BROWSER_TEST_F(ExtensionWindowCreateTest, InvalidCreateWindowState) {
601 EXPECT_TRUE(
602 MatchPattern(RunCreateWindowExpectError(
603 "[{\"state\": \"fullscreen\", \"type\": \"panel\"}]"),
604 keys::kInvalidWindowStateError));
605 EXPECT_TRUE(
606 MatchPattern(RunCreateWindowExpectError(
607 "[{\"state\": \"maximized\", \"type\": \"panel\"}]"),
608 keys::kInvalidWindowStateError));
609 EXPECT_TRUE(
610 MatchPattern(RunCreateWindowExpectError(
611 "[{\"state\": \"minimized\", \"type\": \"panel\"}]"),
612 keys::kInvalidWindowStateError));
613
614 EXPECT_TRUE(
615 MatchPattern(RunCreateWindowExpectError(
616 "[{\"state\": \"minimized\", \"focused\": true}]"),
617 keys::kInvalidWindowStateError));
618
619 EXPECT_TRUE(
620 MatchPattern(RunCreateWindowExpectError(
621 "[{\"state\": \"maximized\", \"focused\": false}]"),
622 keys::kInvalidWindowStateError));
623
624 EXPECT_TRUE(
625 MatchPattern(RunCreateWindowExpectError(
626 "[{\"state\": \"fullscreen\", \"focused\": false}]"),
627 keys::kInvalidWindowStateError));
628
629 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError(
630 "[{\"state\": \"minimized\", \"width\": 500}]"),
631 keys::kInvalidWindowStateError));
632
633 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError(
634 "[{\"state\": \"maximized\", \"width\": 500}]"),
635 keys::kInvalidWindowStateError));
636 EXPECT_TRUE(MatchPattern(RunCreateWindowExpectError(
637 "[{\"state\": \"fullscreen\", \"width\": 500}]"),
638 keys::kInvalidWindowStateError));
639 }
640
564 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { 641 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) {
565 content::OpenURLParams params(GURL(url::kAboutBlankURL), 642 content::OpenURLParams params(GURL(url::kAboutBlankURL),
566 content::Referrer(), 643 content::Referrer(),
567 NEW_FOREGROUND_TAB, 644 NEW_FOREGROUND_TAB,
568 ui::PAGE_TRANSITION_LINK, 645 ui::PAGE_TRANSITION_LINK,
569 false); 646 false);
570 content::WebContents* web_contents = browser()->OpenURL(params); 647 content::WebContents* web_contents = browser()->OpenURL(params);
571 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 648 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
572 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); 649 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
573 int tab_index = -1; 650 int tab_index = -1;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 // Test chrome.tabs.setZoom(). 1071 // Test chrome.tabs.setZoom().
995 error = RunSetZoomExpectError(tab_id, 3.14159); 1072 error = RunSetZoomExpectError(tab_id, 3.14159);
996 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 1073 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
997 1074
998 // chrome.tabs.setZoomSettings(). 1075 // chrome.tabs.setZoomSettings().
999 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); 1076 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab");
1000 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 1077 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
1001 } 1078 }
1002 1079
1003 } // namespace extensions 1080 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698