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

Side by Side Diff: chrome/browser/ui/webui/html_dialog_tab_contents_delegate_unittest.cc

Issue 10214001: WebDialogs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/history/history_types.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/browser_with_test_window_test.h"
16 #include "chrome/test/base/test_browser_window.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/test/web_contents_tester.h"
20 #include "googleurl/src/gurl.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/gfx/rect.h"
24
25 using content::OpenURLParams;
26 using content::Referrer;
27 using content::WebContents;
28 using content::WebContentsTester;
29
30 namespace {
31
32 class TestTabContentsDelegate : public HtmlDialogTabContentsDelegate {
33 public:
34 explicit TestTabContentsDelegate(Profile* profile)
35 : HtmlDialogTabContentsDelegate(profile) {}
36
37 virtual ~TestTabContentsDelegate() {
38 }
39
40 private:
41 DISALLOW_COPY_AND_ASSIGN(TestTabContentsDelegate);
42 };
43
44 class HtmlDialogTabContentsDelegateTest : public BrowserWithTestWindowTest {
45 public:
46 virtual void SetUp() {
47 BrowserWithTestWindowTest::SetUp();
48 test_tab_contents_delegate_.reset(new TestTabContentsDelegate(profile()));
49 }
50
51 virtual void TearDown() {
52 test_tab_contents_delegate_.reset(NULL);
53 BrowserWithTestWindowTest::TearDown();
54 }
55
56 protected:
57 scoped_ptr<TestTabContentsDelegate> test_tab_contents_delegate_;
58 };
59
60 TEST_F(HtmlDialogTabContentsDelegateTest, DoNothingMethodsTest) {
61 // None of the following calls should do anything.
62 EXPECT_TRUE(test_tab_contents_delegate_->IsPopupOrPanel(NULL));
63 scoped_refptr<history::HistoryAddPageArgs> should_add_args(
64 new history::HistoryAddPageArgs(
65 GURL(), base::Time::Now(), 0, 0, GURL(), history::RedirectList(),
66 content::PAGE_TRANSITION_TYPED, history::SOURCE_SYNCED, false));
67 EXPECT_FALSE(test_tab_contents_delegate_->ShouldAddNavigationToHistory(
68 *should_add_args, content::NAVIGATION_TYPE_NEW_PAGE));
69 test_tab_contents_delegate_->NavigationStateChanged(NULL, 0);
70 test_tab_contents_delegate_->ActivateContents(NULL);
71 test_tab_contents_delegate_->LoadingStateChanged(NULL);
72 test_tab_contents_delegate_->CloseContents(NULL);
73 test_tab_contents_delegate_->UpdateTargetURL(NULL, 0, GURL());
74 test_tab_contents_delegate_->MoveContents(NULL, gfx::Rect());
75 EXPECT_EQ(0, browser()->tab_count());
76 EXPECT_EQ(1U, BrowserList::size());
77 }
78
79 TEST_F(HtmlDialogTabContentsDelegateTest, OpenURLFromTabTest) {
80 test_tab_contents_delegate_->OpenURLFromTab(
81 NULL, OpenURLParams(GURL(chrome::kAboutBlankURL), Referrer(),
82 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false));
83 // This should create a new foreground tab in the existing browser.
84 EXPECT_EQ(1, browser()->tab_count());
85 EXPECT_EQ(1U, BrowserList::size());
86 }
87
88 TEST_F(HtmlDialogTabContentsDelegateTest, AddNewContentsForegroundTabTest) {
89 WebContents* contents =
90 WebContentsTester::CreateTestWebContents(profile(), NULL);
91 test_tab_contents_delegate_->AddNewContents(
92 NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), false);
93 // This should create a new foreground tab in the existing browser.
94 EXPECT_EQ(1, browser()->tab_count());
95 EXPECT_EQ(1U, BrowserList::size());
96 }
97
98 TEST_F(HtmlDialogTabContentsDelegateTest, DetachTest) {
99 EXPECT_EQ(profile(), test_tab_contents_delegate_->profile());
100 test_tab_contents_delegate_->Detach();
101 EXPECT_EQ(NULL, test_tab_contents_delegate_->profile());
102 // Now, none of the following calls should do anything.
103 test_tab_contents_delegate_->OpenURLFromTab(
104 NULL, OpenURLParams(GURL(chrome::kAboutBlankURL), Referrer(),
105 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false));
106 test_tab_contents_delegate_->AddNewContents(NULL, NULL, NEW_FOREGROUND_TAB,
107 gfx::Rect(), false);
108 EXPECT_EQ(0, browser()->tab_count());
109 EXPECT_EQ(1U, BrowserList::size());
110 }
111
112 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/html_dialog_tab_contents_delegate.cc ('k') | chrome/browser/ui/webui/html_dialog_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698