OLD | NEW |
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 18 matching lines...) Expand all Loading... |
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 "content/public/browser/navigation_controller.h" | 32 #include "content/public/browser/navigation_controller.h" |
33 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_registrar.h" | 35 #include "content/public/browser/notification_registrar.h" |
36 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
37 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
39 #include "content/public/test/test_browser_thread.h" | |
40 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
41 | 40 |
42 using content::BrowserThread; | |
43 using content::SiteInstance; | 41 using content::SiteInstance; |
44 using content::WebContents; | 42 using content::WebContents; |
45 using extensions::Extension; | 43 using extensions::Extension; |
46 | 44 |
47 namespace { | 45 namespace { |
48 | 46 |
49 // Class used to delete a WebContents when another WebContents is destroyed. | 47 // Class used to delete a WebContents when another WebContents is destroyed. |
50 class DeleteWebContentsOnDestroyedObserver | 48 class DeleteWebContentsOnDestroyedObserver |
51 : public content::NotificationObserver { | 49 : public content::NotificationObserver { |
52 public: | 50 public: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 int id() { return id_; } | 99 int id() { return id_; } |
102 | 100 |
103 private: | 101 private: |
104 int id_; | 102 int id_; |
105 }; | 103 }; |
106 | 104 |
107 } // namespace | 105 } // namespace |
108 | 106 |
109 class TabStripModelTest : public ChromeRenderViewHostTestHarness { | 107 class TabStripModelTest : public ChromeRenderViewHostTestHarness { |
110 public: | 108 public: |
111 TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) { | |
112 } | |
113 | |
114 WebContents* CreateWebContents() { | 109 WebContents* CreateWebContents() { |
115 return WebContents::Create(WebContents::CreateParams(profile())); | 110 return WebContents::Create(WebContents::CreateParams(profile())); |
116 } | 111 } |
117 | 112 |
118 WebContents* CreateWebContentsWithSharedRPH(WebContents* web_contents) { | 113 WebContents* CreateWebContentsWithSharedRPH(WebContents* web_contents) { |
119 WebContents::CreateParams create_params( | 114 WebContents::CreateParams create_params( |
120 profile(), web_contents->GetRenderViewHost()->GetSiteInstance()); | 115 profile(), web_contents->GetRenderViewHost()->GetSiteInstance()); |
121 WebContents* retval = WebContents::Create(create_params); | 116 WebContents* retval = WebContents::Create(create_params); |
122 EXPECT_EQ(retval->GetRenderProcessHost(), | 117 EXPECT_EQ(retval->GetRenderProcessHost(), |
123 web_contents->GetRenderProcessHost()); | 118 web_contents->GetRenderProcessHost()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 std::vector<std::string> selection; | 185 std::vector<std::string> selection; |
191 base::SplitStringAlongWhitespace(selected_tabs, &selection); | 186 base::SplitStringAlongWhitespace(selected_tabs, &selection); |
192 for (size_t i = 0; i < selection.size(); ++i) { | 187 for (size_t i = 0; i < selection.size(); ++i) { |
193 int value; | 188 int value; |
194 ASSERT_TRUE(base::StringToInt(selection[i], &value)); | 189 ASSERT_TRUE(base::StringToInt(selection[i], &value)); |
195 selection_model.AddIndexToSelection(value); | 190 selection_model.AddIndexToSelection(value); |
196 } | 191 } |
197 selection_model.set_active(selection_model.selected_indices()[0]); | 192 selection_model.set_active(selection_model.selected_indices()[0]); |
198 model->SetSelectionFromModel(selection_model); | 193 model->SetSelectionFromModel(selection_model); |
199 } | 194 } |
200 | |
201 private: | |
202 content::TestBrowserThread browser_thread_; | |
203 }; | 195 }; |
204 | 196 |
205 class MockTabStripModelObserver : public TabStripModelObserver { | 197 class MockTabStripModelObserver : public TabStripModelObserver { |
206 public: | 198 public: |
207 explicit MockTabStripModelObserver(TabStripModel* model) | 199 explicit MockTabStripModelObserver(TabStripModel* model) |
208 : empty_(true), | 200 : empty_(true), |
209 model_(model) {} | 201 model_(model) {} |
210 virtual ~MockTabStripModelObserver() {} | 202 virtual ~MockTabStripModelObserver() {} |
211 | 203 |
212 enum TabStripModelObserverAction { | 204 enum TabStripModelObserverAction { |
(...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2333 strip.ActivateTabAt(1, true); | 2325 strip.ActivateTabAt(1, true); |
2334 ASSERT_EQ(1, observer.GetStateCount()); | 2326 ASSERT_EQ(1, observer.GetStateCount()); |
2335 State s(contents2, 1, MockTabStripModelObserver::SELECT); | 2327 State s(contents2, 1, MockTabStripModelObserver::SELECT); |
2336 s.src_contents = contents2; | 2328 s.src_contents = contents2; |
2337 s.src_index = 1; | 2329 s.src_index = 1; |
2338 s.change_reason = TabStripModelObserver::CHANGE_REASON_NONE; | 2330 s.change_reason = TabStripModelObserver::CHANGE_REASON_NONE; |
2339 EXPECT_TRUE(observer.StateEquals(0, s)); | 2331 EXPECT_TRUE(observer.StateEquals(0, s)); |
2340 strip.RemoveObserver(&observer); | 2332 strip.RemoveObserver(&observer); |
2341 strip.CloseAllTabs(); | 2333 strip.CloseAllTabs(); |
2342 } | 2334 } |
OLD | NEW |