Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / ui / webui / web_dialog_web_contents_delegate_unittest.cc
blob0cd677a06600c132860d141eaa3bd89d37040a04
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
3 // found in the LICENSE file.
5 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
7 #include <vector>
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
15 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/browser_with_test_window_test.h"
17 #include "chrome/test/base/test_browser_window.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/history/core/browser/history_types.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/web_contents_tester.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gfx/geometry/rect.h"
25 #include "url/gurl.h"
27 using content::OpenURLParams;
28 using content::Referrer;
29 using content::BrowserContext;
30 using content::WebContents;
31 using content::WebContentsTester;
32 using ui::WebDialogWebContentsDelegate;
34 namespace {
36 class TestWebContentsDelegate : public WebDialogWebContentsDelegate {
37 public:
38 explicit TestWebContentsDelegate(content::BrowserContext* context)
39 : WebDialogWebContentsDelegate(context, new ChromeWebContentsHandler) {
41 ~TestWebContentsDelegate() override {}
43 private:
44 DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate);
47 class WebDialogWebContentsDelegateTest : public BrowserWithTestWindowTest {
48 public:
49 void SetUp() override {
50 BrowserWithTestWindowTest::SetUp();
51 test_web_contents_delegate_.reset(new TestWebContentsDelegate(profile()));
54 void TearDown() override {
55 test_web_contents_delegate_.reset(NULL);
56 BrowserWithTestWindowTest::TearDown();
59 protected:
60 scoped_ptr<TestWebContentsDelegate> test_web_contents_delegate_;
63 TEST_F(WebDialogWebContentsDelegateTest, DoNothingMethodsTest) {
64 // None of the following calls should do anything.
65 EXPECT_TRUE(test_web_contents_delegate_->IsPopupOrPanel(NULL));
66 history::HistoryAddPageArgs should_add_args(
67 GURL(), base::Time::Now(), 0, 0, GURL(), history::RedirectList(),
68 ui::PAGE_TRANSITION_TYPED, history::SOURCE_SYNCED, false);
69 test_web_contents_delegate_->NavigationStateChanged(
70 NULL, content::InvalidateTypes(0));
71 test_web_contents_delegate_->ActivateContents(NULL);
72 test_web_contents_delegate_->LoadingStateChanged(NULL, true);
73 test_web_contents_delegate_->CloseContents(NULL);
74 test_web_contents_delegate_->UpdateTargetURL(NULL, GURL());
75 test_web_contents_delegate_->MoveContents(NULL, gfx::Rect());
76 EXPECT_EQ(0, browser()->tab_strip_model()->count());
77 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
80 TEST_F(WebDialogWebContentsDelegateTest, OpenURLFromTabTest) {
81 test_web_contents_delegate_->OpenURLFromTab(
82 NULL,
83 OpenURLParams(GURL(url::kAboutBlankURL),
84 Referrer(),
85 NEW_FOREGROUND_TAB,
86 ui::PAGE_TRANSITION_LINK,
87 false));
88 // This should create a new foreground tab in the existing browser.
89 EXPECT_EQ(1, browser()->tab_strip_model()->count());
90 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
93 TEST_F(WebDialogWebContentsDelegateTest, AddNewContentsForegroundTabTest) {
94 WebContents* contents =
95 WebContentsTester::CreateTestWebContents(profile(), NULL);
96 test_web_contents_delegate_->AddNewContents(
97 NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), false, NULL);
98 // This should create a new foreground tab in the existing browser.
99 EXPECT_EQ(1, browser()->tab_strip_model()->count());
100 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
103 TEST_F(WebDialogWebContentsDelegateTest, DetachTest) {
104 EXPECT_EQ(profile(), test_web_contents_delegate_->browser_context());
105 test_web_contents_delegate_->Detach();
106 EXPECT_EQ(NULL, test_web_contents_delegate_->browser_context());
107 // Now, none of the following calls should do anything.
108 test_web_contents_delegate_->OpenURLFromTab(
109 NULL,
110 OpenURLParams(GURL(url::kAboutBlankURL),
111 Referrer(),
112 NEW_FOREGROUND_TAB,
113 ui::PAGE_TRANSITION_LINK,
114 false));
115 test_web_contents_delegate_->AddNewContents(NULL, NULL, NEW_FOREGROUND_TAB,
116 gfx::Rect(), false, NULL);
117 EXPECT_EQ(0, browser()->tab_strip_model()->count());
118 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
121 } // namespace