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

Side by Side Diff: chrome/browser/ui/tabs/tab_strip_model_unittest.cc

Issue 23311008: Tab Strip: Initialize the blocked state for a tab. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix test for win aura Created 7 years, 3 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/tabs/tab_strip_model.cc ('k') | no next file » | 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/tabs/tab_strip_model.h" 5 #include "chrome/browser/ui/tabs/tab_strip_model.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
26 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" 26 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
28 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 30 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "components/web_modal/web_contents_modal_dialog_manager.h"
32 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
39 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
40 41
41 using content::SiteInstance; 42 using content::SiteInstance;
42 using content::WebContents; 43 using content::WebContents;
43 using extensions::Extension; 44 using extensions::Extension;
45 using web_modal::NativeWebContentsModalDialog;
44 46
45 namespace { 47 namespace {
46 48
47 // Class used to delete a WebContents and TabStripModel when another WebContents 49 // Class used to delete a WebContents and TabStripModel when another WebContents
48 // is destroyed. 50 // is destroyed.
49 class DeleteWebContentsOnDestroyedObserver 51 class DeleteWebContentsOnDestroyedObserver
50 : public content::NotificationObserver { 52 : public content::NotificationObserver {
51 public: 53 public:
52 // When |source| is deleted both |tab_to_delete| and |tab_strip| are deleted. 54 // When |source| is deleted both |tab_to_delete| and |tab_strip| are deleted.
53 // |tab_to_delete| and |tab_strip| may be NULL. 55 // |tab_to_delete| and |tab_strip| may be NULL.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 class TabStripModelTestIDUserData : public base::SupportsUserData::Data { 106 class TabStripModelTestIDUserData : public base::SupportsUserData::Data {
105 public: 107 public:
106 explicit TabStripModelTestIDUserData(int id) : id_(id) {} 108 explicit TabStripModelTestIDUserData(int id) : id_(id) {}
107 virtual ~TabStripModelTestIDUserData() {} 109 virtual ~TabStripModelTestIDUserData() {}
108 int id() { return id_; } 110 int id() { return id_; }
109 111
110 private: 112 private:
111 int id_; 113 int id_;
112 }; 114 };
113 115
116 class DummyNativeWebContentsModalDialogManager
117 : public web_modal::NativeWebContentsModalDialogManager {
118 public:
119 explicit DummyNativeWebContentsModalDialogManager(
120 web_modal::NativeWebContentsModalDialogManagerDelegate* delegate)
121 : delegate_(delegate) {}
122 virtual ~DummyNativeWebContentsModalDialogManager() {}
123
124 virtual void ManageDialog(NativeWebContentsModalDialog dialog) OVERRIDE {}
125 virtual void ShowDialog(NativeWebContentsModalDialog dialog) OVERRIDE {}
126 virtual void HideDialog(NativeWebContentsModalDialog dialog) OVERRIDE {}
127 virtual void CloseDialog(NativeWebContentsModalDialog dialog) OVERRIDE {
128 delegate_->WillClose(dialog);
129 }
130 virtual void FocusDialog(NativeWebContentsModalDialog dialog) OVERRIDE {}
131 virtual void PulseDialog(NativeWebContentsModalDialog dialog) OVERRIDE {}
132 virtual void HostChanged(
133 web_modal::WebContentsModalDialogHost* new_host) OVERRIDE {}
134
135 private:
136 web_modal::NativeWebContentsModalDialogManagerDelegate* delegate_;
137
138 DISALLOW_COPY_AND_ASSIGN(DummyNativeWebContentsModalDialogManager);
139 };
140
141 // Test Browser-like class for TabStripModelTest.TabBlockedState.
142 class TabBlockedStateTestBrowser
143 : public TabStripModelObserver,
144 public web_modal::WebContentsModalDialogManagerDelegate {
145 public:
146 explicit TabBlockedStateTestBrowser(TabStripModel* tab_strip_model)
147 : tab_strip_model_(tab_strip_model) {
148 tab_strip_model_->AddObserver(this);
149 }
150
151 virtual ~TabBlockedStateTestBrowser() {
152 tab_strip_model_->RemoveObserver(this);
153 }
154
155 private:
156 // TabStripModelObserver
157 virtual void TabInsertedAt(WebContents* contents,
158 int index,
159 bool foreground) OVERRIDE {
160 web_modal::WebContentsModalDialogManager* manager =
161 web_modal::WebContentsModalDialogManager::FromWebContents(contents);
162 if (manager)
163 manager->SetDelegate(this);
164 }
165
166 // WebContentsModalDialogManagerDelegate
167 virtual void SetWebContentsBlocked(content::WebContents* contents,
168 bool blocked) OVERRIDE {
169 int index = tab_strip_model_->GetIndexOfWebContents(contents);
170 ASSERT_GE(index, 0);
171 tab_strip_model_->SetTabBlocked(index, blocked);
172 }
173
174 TabStripModel* tab_strip_model_;
175
176 DISALLOW_COPY_AND_ASSIGN(TabBlockedStateTestBrowser);
177 };
178
114 } // namespace 179 } // namespace
115 180
116 class TabStripModelTest : public ChromeRenderViewHostTestHarness { 181 class TabStripModelTest : public ChromeRenderViewHostTestHarness {
117 public: 182 public:
118 WebContents* CreateWebContents() { 183 WebContents* CreateWebContents() {
119 return WebContents::Create(WebContents::CreateParams(profile())); 184 return WebContents::Create(WebContents::CreateParams(profile()));
120 } 185 }
121 186
122 WebContents* CreateWebContentsWithSharedRPH(WebContents* web_contents) { 187 WebContents* CreateWebContentsWithSharedRPH(WebContents* web_contents) {
123 WebContents::CreateParams create_params( 188 WebContents::CreateParams create_params(
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 strip.ActivateTabAt(1, true); 2424 strip.ActivateTabAt(1, true);
2360 ASSERT_EQ(1, observer.GetStateCount()); 2425 ASSERT_EQ(1, observer.GetStateCount());
2361 State s(contents2, 1, MockTabStripModelObserver::SELECT); 2426 State s(contents2, 1, MockTabStripModelObserver::SELECT);
2362 s.src_contents = contents2; 2427 s.src_contents = contents2;
2363 s.src_index = 1; 2428 s.src_index = 1;
2364 s.change_reason = TabStripModelObserver::CHANGE_REASON_NONE; 2429 s.change_reason = TabStripModelObserver::CHANGE_REASON_NONE;
2365 EXPECT_TRUE(observer.StateEquals(0, s)); 2430 EXPECT_TRUE(observer.StateEquals(0, s));
2366 strip.RemoveObserver(&observer); 2431 strip.RemoveObserver(&observer);
2367 strip.CloseAllTabs(); 2432 strip.CloseAllTabs();
2368 } 2433 }
2434
2435 // Verifies a newly inserted tab retains its previous blocked state.
2436 // http://crbug.com/276334
2437 TEST_F(TabStripModelTest, TabBlockedState) {
2438 // Start with a source tab strip.
2439 TabStripDummyDelegate dummy_tab_strip_delegate;
2440 TabStripModel strip_src(&dummy_tab_strip_delegate, profile());
2441 TabBlockedStateTestBrowser browser_src(&strip_src);
2442
2443 // Add a tab.
2444 WebContents* contents1 = CreateWebContents();
2445 web_modal::WebContentsModalDialogManager::CreateForWebContents(contents1);
2446 strip_src.AppendWebContents(contents1, false);
2447
2448 // Add another tab.
2449 WebContents* contents2 = CreateWebContents();
2450 web_modal::WebContentsModalDialogManager::CreateForWebContents(contents2);
2451 strip_src.AppendWebContents(contents2, false);
2452
2453 // Create a destination tab strip.
2454 TabStripModel strip_dst(&dummy_tab_strip_delegate, profile());
2455 TabBlockedStateTestBrowser browser_dst(&strip_dst);
2456
2457 // Setup a NativeWebContentsModalDialogManager for tab |contents2|.
2458 web_modal::WebContentsModalDialogManager* modal_dialog_manager =
2459 web_modal::WebContentsModalDialogManager::FromWebContents(contents2);
2460 web_modal::WebContentsModalDialogManager::TestApi test_api(
2461 modal_dialog_manager);
2462 test_api.ResetNativeManager(
2463 new DummyNativeWebContentsModalDialogManager(modal_dialog_manager));
2464
2465 // Show a dialog that blocks tab |contents2|.
2466 // DummyNativeWebContentsModalDialogManager doesn't care about the
2467 // NativeWebContentsModalDialog value, so any dummy value works.
2468 modal_dialog_manager->ShowDialog(
2469 reinterpret_cast<NativeWebContentsModalDialog>(0));
2470 EXPECT_TRUE(strip_src.IsTabBlocked(1));
2471
2472 // Detach the tab.
2473 WebContents* moved_contents = strip_src.DetachWebContentsAt(1);
2474 EXPECT_EQ(contents2, moved_contents);
2475
2476 // Attach the tab to the destination tab strip.
2477 strip_dst.AppendWebContents(moved_contents, true);
2478 EXPECT_TRUE(strip_dst.IsTabBlocked(0));
2479
2480 strip_dst.CloseAllTabs();
2481 strip_src.CloseAllTabs();
2482 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698