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 and TabStripModel when another WebContents | 47 // Class used to delete a WebContents and TabStripModel when another WebContents |
50 // is destroyed. | 48 // is destroyed. |
51 class DeleteWebContentsOnDestroyedObserver | 49 class DeleteWebContentsOnDestroyedObserver |
52 : public content::NotificationObserver { | 50 : public content::NotificationObserver { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 int id() { return id_; } | 108 int id() { return id_; } |
111 | 109 |
112 private: | 110 private: |
113 int id_; | 111 int id_; |
114 }; | 112 }; |
115 | 113 |
116 } // namespace | 114 } // namespace |
117 | 115 |
118 class TabStripModelTest : public ChromeRenderViewHostTestHarness { | 116 class TabStripModelTest : public ChromeRenderViewHostTestHarness { |
119 public: | 117 public: |
120 TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) { | |
121 } | |
122 | |
123 WebContents* CreateWebContents() { | 118 WebContents* CreateWebContents() { |
124 return WebContents::Create(WebContents::CreateParams(profile())); | 119 return WebContents::Create(WebContents::CreateParams(profile())); |
125 } | 120 } |
126 | 121 |
127 WebContents* CreateWebContentsWithSharedRPH(WebContents* web_contents) { | 122 WebContents* CreateWebContentsWithSharedRPH(WebContents* web_contents) { |
128 WebContents::CreateParams create_params( | 123 WebContents::CreateParams create_params( |
129 profile(), web_contents->GetRenderViewHost()->GetSiteInstance()); | 124 profile(), web_contents->GetRenderViewHost()->GetSiteInstance()); |
130 WebContents* retval = WebContents::Create(create_params); | 125 WebContents* retval = WebContents::Create(create_params); |
131 EXPECT_EQ(retval->GetRenderProcessHost(), | 126 EXPECT_EQ(retval->GetRenderProcessHost(), |
132 web_contents->GetRenderProcessHost()); | 127 web_contents->GetRenderProcessHost()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 std::vector<std::string> selection; | 194 std::vector<std::string> selection; |
200 base::SplitStringAlongWhitespace(selected_tabs, &selection); | 195 base::SplitStringAlongWhitespace(selected_tabs, &selection); |
201 for (size_t i = 0; i < selection.size(); ++i) { | 196 for (size_t i = 0; i < selection.size(); ++i) { |
202 int value; | 197 int value; |
203 ASSERT_TRUE(base::StringToInt(selection[i], &value)); | 198 ASSERT_TRUE(base::StringToInt(selection[i], &value)); |
204 selection_model.AddIndexToSelection(value); | 199 selection_model.AddIndexToSelection(value); |
205 } | 200 } |
206 selection_model.set_active(selection_model.selected_indices()[0]); | 201 selection_model.set_active(selection_model.selected_indices()[0]); |
207 model->SetSelectionFromModel(selection_model); | 202 model->SetSelectionFromModel(selection_model); |
208 } | 203 } |
209 | |
210 private: | |
211 content::TestBrowserThread browser_thread_; | |
212 }; | 204 }; |
213 | 205 |
214 class MockTabStripModelObserver : public TabStripModelObserver { | 206 class MockTabStripModelObserver : public TabStripModelObserver { |
215 public: | 207 public: |
216 explicit MockTabStripModelObserver(TabStripModel* model) | 208 explicit MockTabStripModelObserver(TabStripModel* model) |
217 : empty_(true), | 209 : empty_(true), |
218 deleted_(false), | 210 deleted_(false), |
219 model_(model) {} | 211 model_(model) {} |
220 virtual ~MockTabStripModelObserver() {} | 212 virtual ~MockTabStripModelObserver() {} |
221 | 213 |
(...skipping 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 strip.ActivateTabAt(1, true); | 2359 strip.ActivateTabAt(1, true); |
2368 ASSERT_EQ(1, observer.GetStateCount()); | 2360 ASSERT_EQ(1, observer.GetStateCount()); |
2369 State s(contents2, 1, MockTabStripModelObserver::SELECT); | 2361 State s(contents2, 1, MockTabStripModelObserver::SELECT); |
2370 s.src_contents = contents2; | 2362 s.src_contents = contents2; |
2371 s.src_index = 1; | 2363 s.src_index = 1; |
2372 s.change_reason = TabStripModelObserver::CHANGE_REASON_NONE; | 2364 s.change_reason = TabStripModelObserver::CHANGE_REASON_NONE; |
2373 EXPECT_TRUE(observer.StateEquals(0, s)); | 2365 EXPECT_TRUE(observer.StateEquals(0, s)); |
2374 strip.RemoveObserver(&observer); | 2366 strip.RemoveObserver(&observer); |
2375 strip.CloseAllTabs(); | 2367 strip.CloseAllTabs(); |
2376 } | 2368 } |
OLD | NEW |