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

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

Powered by Google App Engine
This is Rietveld 408576698