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

Side by Side Diff: chrome/browser/dom_ui/html_dialog_tab_contents_delegate_unittest.cc

Issue 4055004: Change window opening behavior for HtmlDialogTabContentsDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased from trunk and fixed comments in HtmlDialogTabContentsDelegate Created 10 years, 1 month 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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/dom_ui/html_dialog_tab_contents_delegate.h" 5 #include "chrome/browser/dom_ui/html_dialog_tab_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/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_list.h" 12 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/history/history_types.h" 13 #include "chrome/browser/history/history_types.h"
14 #include "chrome/browser/tab_contents/test_tab_contents.h" 14 #include "chrome/browser/tab_contents/test_tab_contents.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "chrome/test/browser_with_test_window_test.h" 16 #include "chrome/test/browser_with_test_window_test.h"
17 #include "chrome/test/test_browser_window.h" 17 #include "chrome/test/test_browser_window.h"
18 #include "chrome/test/testing_profile.h" 18 #include "chrome/test/testing_profile.h"
19 #include "gfx/rect.h" 19 #include "gfx/rect.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 23
24 namespace { 24 namespace {
25 25
26 class MockTestBrowserWindow : public TestBrowserWindow {
27 public:
28 // TestBrowserWindow() doesn't actually use its browser argument so we just
29 // pass NULL.
30 MockTestBrowserWindow() : TestBrowserWindow(NULL) {}
31
32 virtual ~MockTestBrowserWindow() {}
33
34 MOCK_METHOD0(Show, void());
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(MockTestBrowserWindow);
38 };
39
40 class TestTabContentsDelegate : public HtmlDialogTabContentsDelegate { 26 class TestTabContentsDelegate : public HtmlDialogTabContentsDelegate {
41 public: 27 public:
42 explicit TestTabContentsDelegate(Profile* profile) 28 explicit TestTabContentsDelegate(Profile* profile)
43 : HtmlDialogTabContentsDelegate(profile), 29 : HtmlDialogTabContentsDelegate(profile) {}
44 window_for_next_created_browser_(NULL) {}
45 30
46 virtual ~TestTabContentsDelegate() { 31 virtual ~TestTabContentsDelegate() {
47 CHECK(!window_for_next_created_browser_);
48 for (std::vector<Browser*>::iterator i = created_browsers_.begin();
49 i != created_browsers_.end(); ++i) {
50 (*i)->CloseAllTabs();
51 // We need to explicitly cast this since BrowserWindow does *not*
52 // have a virtual destructor.
53 delete static_cast<MockTestBrowserWindow*>((*i)->window());
54 delete *i;
55 }
56 } 32 }
57 33
58 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} 34 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
59 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} 35 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
60 36
61 // Takes ownership of window.
62 void SetWindowForNextCreatedBrowser(BrowserWindow* window) {
63 CHECK(window);
64 window_for_next_created_browser_ = window;
65 }
66
67 protected:
68 // CreateBrowser() is called by OpenURLFromTab() and AddNewContents().
69 virtual Browser* CreateBrowser() {
70 DCHECK(profile());
71 DCHECK(window_for_next_created_browser_);
72 Browser* browser = new Browser(Browser::TYPE_NORMAL, profile());
73 browser->set_window(window_for_next_created_browser_);
74 window_for_next_created_browser_ = NULL;
75 created_browsers_.push_back(browser);
76 return browser;
77 }
78
79 private: 37 private:
80 BrowserWindow* window_for_next_created_browser_;
81 std::vector<Browser*> created_browsers_;
82
83 DISALLOW_COPY_AND_ASSIGN(TestTabContentsDelegate); 38 DISALLOW_COPY_AND_ASSIGN(TestTabContentsDelegate);
84 }; 39 };
85 40
86 class HtmlDialogTabContentsDelegateTest : public BrowserWithTestWindowTest { 41 class HtmlDialogTabContentsDelegateTest : public BrowserWithTestWindowTest {
87 public: 42 public:
88 virtual void SetUp() { 43 virtual void SetUp() {
89 BrowserWithTestWindowTest::SetUp(); 44 BrowserWithTestWindowTest::SetUp();
90 test_tab_contents_delegate_.reset(new TestTabContentsDelegate(profile())); 45 test_tab_contents_delegate_.reset(new TestTabContentsDelegate(profile()));
91 } 46 }
92 47
(...skipping 24 matching lines...) Expand all
117 // there's http://code.google.com/p/chromium/issues/detail?id=24885 on 72 // there's http://code.google.com/p/chromium/issues/detail?id=24885 on
118 // death tests on Windows so we simply don't call it. 73 // death tests on Windows so we simply don't call it.
119 test_tab_contents_delegate_->UpdateTargetURL(NULL, GURL()); 74 test_tab_contents_delegate_->UpdateTargetURL(NULL, GURL());
120 test_tab_contents_delegate_->MoveContents(NULL, gfx::Rect()); 75 test_tab_contents_delegate_->MoveContents(NULL, gfx::Rect());
121 test_tab_contents_delegate_->ToolbarSizeChanged(NULL, false); 76 test_tab_contents_delegate_->ToolbarSizeChanged(NULL, false);
122 EXPECT_EQ(0, browser()->tab_count()); 77 EXPECT_EQ(0, browser()->tab_count());
123 EXPECT_EQ(1U, BrowserList::size()); 78 EXPECT_EQ(1U, BrowserList::size());
124 } 79 }
125 80
126 TEST_F(HtmlDialogTabContentsDelegateTest, OpenURLFromTabTest) { 81 TEST_F(HtmlDialogTabContentsDelegateTest, OpenURLFromTabTest) {
127 MockTestBrowserWindow* window = new MockTestBrowserWindow();
128 EXPECT_CALL(*window, Show()).Times(1);
129 test_tab_contents_delegate_->SetWindowForNextCreatedBrowser(window);
130
131 test_tab_contents_delegate_->OpenURLFromTab( 82 test_tab_contents_delegate_->OpenURLFromTab(
132 NULL, GURL(chrome::kAboutBlankURL), GURL(), 83 NULL, GURL(chrome::kAboutBlankURL), GURL(),
133 NEW_FOREGROUND_TAB, PageTransition::LINK); 84 NEW_FOREGROUND_TAB, PageTransition::LINK);
134 EXPECT_EQ(0, browser()->tab_count()); 85 // This should create a new foreground tab in the existing browser.
135 EXPECT_EQ(2U, BrowserList::size()); 86 EXPECT_EQ(1, browser()->tab_count());
87 EXPECT_EQ(1U, BrowserList::size());
136 } 88 }
137 89
138 TEST_F(HtmlDialogTabContentsDelegateTest, AddNewContentsTest) { 90 TEST_F(HtmlDialogTabContentsDelegateTest, AddNewContentsForegroundTabTest) {
139 MockTestBrowserWindow* window = new MockTestBrowserWindow();
140 EXPECT_CALL(*window, Show()).Times(1);
141 test_tab_contents_delegate_->SetWindowForNextCreatedBrowser(window);
142
143 TabContents* contents = 91 TabContents* contents =
144 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); 92 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
145 test_tab_contents_delegate_->AddNewContents( 93 test_tab_contents_delegate_->AddNewContents(
146 NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), false); 94 NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), false);
147 EXPECT_EQ(0, browser()->tab_count()); 95 // This should create a new foreground tab in the existing browser.
148 EXPECT_EQ(2U, BrowserList::size()); 96 EXPECT_EQ(1, browser()->tab_count());
97 EXPECT_EQ(1U, BrowserList::size());
149 } 98 }
150 99
151 TEST_F(HtmlDialogTabContentsDelegateTest, DetachTest) { 100 TEST_F(HtmlDialogTabContentsDelegateTest, DetachTest) {
152 EXPECT_EQ(profile(), test_tab_contents_delegate_->profile()); 101 EXPECT_EQ(profile(), test_tab_contents_delegate_->profile());
153 test_tab_contents_delegate_->Detach(); 102 test_tab_contents_delegate_->Detach();
154 EXPECT_EQ(NULL, test_tab_contents_delegate_->profile()); 103 EXPECT_EQ(NULL, test_tab_contents_delegate_->profile());
155 // Now, none of the following calls should do anything. 104 // Now, none of the following calls should do anything.
156 test_tab_contents_delegate_->OpenURLFromTab( 105 test_tab_contents_delegate_->OpenURLFromTab(
157 NULL, GURL(chrome::kAboutBlankURL), GURL(), 106 NULL, GURL(chrome::kAboutBlankURL), GURL(),
158 NEW_FOREGROUND_TAB, PageTransition::LINK); 107 NEW_FOREGROUND_TAB, PageTransition::LINK);
159 test_tab_contents_delegate_->AddNewContents(NULL, NULL, NEW_FOREGROUND_TAB, 108 test_tab_contents_delegate_->AddNewContents(NULL, NULL, NEW_FOREGROUND_TAB,
160 gfx::Rect(), false); 109 gfx::Rect(), false);
161 EXPECT_EQ(0, browser()->tab_count()); 110 EXPECT_EQ(0, browser()->tab_count());
162 EXPECT_EQ(1U, BrowserList::size()); 111 EXPECT_EQ(1U, BrowserList::size());
163 } 112 }
164 113
165 } // namespace 114 } // namespace
166
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc ('k') | chrome/browser/views/bookmark_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698