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

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

Issue 2630583002: Add setting to isolate zoom changes by default. (Closed)
Patch Set: Add more tests. Created 3 years, 11 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 20 matching lines...) Expand all
31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
32 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
33 #include "components/web_modal/web_contents_modal_dialog_manager.h" 33 #include "components/web_modal/web_contents_modal_dialog_manager.h"
34 #include "content/public/browser/navigation_controller.h" 34 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/render_process_host.h" 36 #include "content/public/browser/render_process_host.h"
37 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
38 #include "content/public/browser/web_contents_observer.h" 38 #include "content/public/browser/web_contents_observer.h"
39 #include "content/public/test/web_contents_tester.h" 39 #include "content/public/test/web_contents_tester.h"
40 #include "extensions/common/extension.h" 40 #include "extensions/common/extension.h"
41 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
42 43
43 using content::SiteInstance; 44 using content::SiteInstance;
44 using content::WebContents; 45 using content::WebContents;
45 using content::WebContentsTester; 46 using content::WebContentsTester;
46 using extensions::Extension; 47 using extensions::Extension;
47 48
48 namespace { 49 namespace {
49 50
50 // Class used to delete a WebContents and TabStripModel when another WebContents 51 // Class used to delete a WebContents and TabStripModel when another WebContents
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 426
426 private: 427 private:
427 std::vector<State> states_; 428 std::vector<State> states_;
428 429
429 bool empty_; 430 bool empty_;
430 TabStripModel* model_; 431 TabStripModel* model_;
431 432
432 DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver); 433 DISALLOW_COPY_AND_ASSIGN(MockTabStripModelObserver);
433 }; 434 };
434 435
436 class MockWebContentsObserver : public content::WebContentsObserver {
437 public:
438 explicit MockWebContentsObserver(WebContents* web_contents)
439 : WebContentsObserver(web_contents) {}
440 MOCK_METHOD2(
441 WebContentsReplaced,
442 void(WebContents* old_web_contents, WebContents* new_web_contents));
443 };
444
435 TEST_F(TabStripModelTest, TestBasicAPI) { 445 TEST_F(TabStripModelTest, TestBasicAPI) {
436 TabStripDummyDelegate delegate; 446 TabStripDummyDelegate delegate;
437 TabStripModel tabstrip(&delegate, profile()); 447 TabStripModel tabstrip(&delegate, profile());
438 MockTabStripModelObserver observer(&tabstrip); 448 MockTabStripModelObserver observer(&tabstrip);
439 tabstrip.AddObserver(&observer); 449 tabstrip.AddObserver(&observer);
440 450
441 EXPECT_TRUE(tabstrip.empty()); 451 EXPECT_TRUE(tabstrip.empty());
442 452
443 typedef MockTabStripModelObserver::State State; 453 typedef MockTabStripModelObserver::State State;
444 454
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 2127
2118 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); 2128 ASSERT_EQ(1, tabstrip_observer.GetStateCount());
2119 2129
2120 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED); 2130 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED);
2121 state.src_contents = third_contents; 2131 state.src_contents = third_contents;
2122 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); 2132 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state));
2123 2133
2124 strip.CloseAllTabs(); 2134 strip.CloseAllTabs();
2125 } 2135 }
2126 2136
2137 // Makes sure the TabStripModel notifies a WebContents during its replacement.
2138 TEST_F(TabStripModelTest, ReplaceNotifiesWebContents) {
2139 TabStripDummyDelegate delegate;
2140 TabStripModel strip(&delegate, profile());
2141
2142 WebContents* contents1 = CreateWebContents();
2143 WebContents* contents2 = CreateWebContents();
2144 strip.AppendWebContents(contents1, true);
2145
2146 MockWebContentsObserver observer(contents1);
2147 EXPECT_CALL(observer, WebContentsReplaced(contents1, contents2));
2148 delete strip.ReplaceWebContentsAt(0, contents2);
2149
2150 strip.CloseAllTabs();
2151 }
2152
2127 // Makes sure TabStripModel handles the case of deleting a tab while removing 2153 // Makes sure TabStripModel handles the case of deleting a tab while removing
2128 // another tab. 2154 // another tab.
2129 TEST_F(TabStripModelTest, DeleteFromDestroy) { 2155 TEST_F(TabStripModelTest, DeleteFromDestroy) {
2130 TabStripDummyDelegate delegate; 2156 TabStripDummyDelegate delegate;
2131 TabStripModel strip(&delegate, profile()); 2157 TabStripModel strip(&delegate, profile());
2132 WebContents* contents1 = CreateWebContents(); 2158 WebContents* contents1 = CreateWebContents();
2133 WebContents* contents2 = CreateWebContents(); 2159 WebContents* contents2 = CreateWebContents();
2134 MockTabStripModelObserver tab_strip_model_observer(&strip); 2160 MockTabStripModelObserver tab_strip_model_observer(&strip);
2135 strip.AppendWebContents(contents1, true); 2161 strip.AppendWebContents(contents1, true);
2136 strip.AppendWebContents(contents2, true); 2162 strip.AppendWebContents(contents2, true);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 strip.AddObserver(&observer); 2570 strip.AddObserver(&observer);
2545 2571
2546 strip.ActivateTabAt(1, true); 2572 strip.ActivateTabAt(1, true);
2547 EXPECT_EQ(1, strip.active_index()); 2573 EXPECT_EQ(1, strip.active_index());
2548 2574
2549 strip.MoveWebContentsAt(2, 3, true); 2575 strip.MoveWebContentsAt(2, 3, true);
2550 EXPECT_EQ(3, strip.active_index()); 2576 EXPECT_EQ(3, strip.active_index());
2551 2577
2552 strip.CloseAllTabs(); 2578 strip.CloseAllTabs();
2553 } 2579 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698