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

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

Issue 10831407: Kill PropertyBag, switch WebContents to SupportsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 8 years, 4 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
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/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/property_bag.h"
15 #include "base/stl_util.h" 14 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
17 #include "base/string_split.h" 16 #include "base/string_split.h"
18 #include "base/string_util.h" 17 #include "base/string_util.h"
19 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/defaults.h" 19 #include "chrome/browser/defaults.h"
21 #include "chrome/browser/extensions/tab_helper.h" 20 #include "chrome/browser/extensions/tab_helper.h"
22 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // A dummy TabContents we give to callers that expect us to actually 109 // A dummy TabContents we give to callers that expect us to actually
111 // build a Destinations tab for them. 110 // build a Destinations tab for them.
112 TabContents* dummy_contents_; 111 TabContents* dummy_contents_;
113 112
114 // Whether to report that we need to run an unload listener before closing. 113 // Whether to report that we need to run an unload listener before closing.
115 bool run_unload_; 114 bool run_unload_;
116 115
117 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); 116 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate);
118 }; 117 };
119 118
119 namespace {
120
121 const char kTabStripModelTestIDUserDataKey[] = "TabStripModelTestIDUserData";
122
123 class TabStripModelTestIDUserData : public base::SupportsUserData::Data {
124 public:
125 explicit TabStripModelTestIDUserData(int id) : id_(id) {}
126 virtual ~TabStripModelTestIDUserData() {}
127 int id() { return id_; }
128
129 private:
130 int id_;
131 };
132
133 } // namespace
134
120 class TabStripModelTest : public ChromeRenderViewHostTestHarness { 135 class TabStripModelTest : public ChromeRenderViewHostTestHarness {
121 public: 136 public:
122 TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) { 137 TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) {
123 } 138 }
124 139
125 TabContents* CreateTabContents() { 140 TabContents* CreateTabContents() {
126 return chrome::TabContentsFactory(profile(), NULL, MSG_ROUTING_NONE, NULL); 141 return chrome::TabContentsFactory(profile(), NULL, MSG_ROUTING_NONE, NULL);
127 } 142 }
128 143
129 TabContents* CreateTabContentsWithSharedRPH( 144 TabContents* CreateTabContentsWithSharedRPH(
(...skipping 20 matching lines...) Expand all
150 void GoForward(WebContents* contents) { 165 void GoForward(WebContents* contents) {
151 controller().GoForward(); 166 controller().GoForward();
152 } 167 }
153 168
154 void SwitchTabTo(WebContents* contents) { 169 void SwitchTabTo(WebContents* contents) {
155 // contents()->WasShown(); 170 // contents()->WasShown();
156 } 171 }
157 172
158 // Sets the id of the specified contents. 173 // Sets the id of the specified contents.
159 void SetID(WebContents* contents, int id) { 174 void SetID(WebContents* contents, int id) {
160 GetIDAccessor()->SetProperty(contents->GetPropertyBag(), id); 175 contents->SetUserData(&kTabStripModelTestIDUserDataKey,
176 new TabStripModelTestIDUserData(id));
161 } 177 }
162 178
163 // Returns the id of the specified contents. 179 // Returns the id of the specified contents.
164 int GetID(WebContents* contents) { 180 int GetID(WebContents* contents) {
165 return *GetIDAccessor()->GetProperty(contents->GetPropertyBag()); 181 TabStripModelTestIDUserData* user_data =
182 static_cast<TabStripModelTestIDUserData*>(
183 contents->GetUserData(&kTabStripModelTestIDUserDataKey));
184
185 return user_data ? user_data->id() : -1;
166 } 186 }
167 187
168 // Returns the state of the given tab strip as a string. The state consists 188 // Returns the state of the given tab strip as a string. The state consists
169 // of the ID of each tab contents followed by a 'p' if pinned. For example, 189 // of the ID of each tab contents followed by a 'p' if pinned. For example,
170 // if the model consists of two tabs with ids 2 and 1, with the first 190 // if the model consists of two tabs with ids 2 and 1, with the first
171 // tab pinned, this returns "2p 1". 191 // tab pinned, this returns "2p 1".
172 std::string GetPinnedState(const TabStripModel& model) { 192 std::string GetPinnedState(const TabStripModel& model) {
173 std::string actual; 193 std::string actual;
174 for (int i = 0; i < model.count(); ++i) { 194 for (int i = 0; i < model.count(); ++i) {
175 if (i > 0) 195 if (i > 0)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 for (size_t i = 0; i < selection.size(); ++i) { 239 for (size_t i = 0; i < selection.size(); ++i) {
220 int value; 240 int value;
221 ASSERT_TRUE(base::StringToInt(selection[i], &value)); 241 ASSERT_TRUE(base::StringToInt(selection[i], &value));
222 selection_model.AddIndexToSelection(value); 242 selection_model.AddIndexToSelection(value);
223 } 243 }
224 selection_model.set_active(selection_model.selected_indices()[0]); 244 selection_model.set_active(selection_model.selected_indices()[0]);
225 model->SetSelectionFromModel(selection_model); 245 model->SetSelectionFromModel(selection_model);
226 } 246 }
227 247
228 private: 248 private:
229 base::PropertyAccessor<int>* GetIDAccessor() {
230 static base::PropertyAccessor<int> accessor;
231 return &accessor;
232 }
233
234 content::TestBrowserThread browser_thread_; 249 content::TestBrowserThread browser_thread_;
235 250
236 std::wstring test_dir_; 251 std::wstring test_dir_;
237 std::wstring profile_path_; 252 std::wstring profile_path_;
238 }; 253 };
239 254
240 class MockTabStripModelObserver : public TabStripModelObserver { 255 class MockTabStripModelObserver : public TabStripModelObserver {
241 public: 256 public:
242 MockTabStripModelObserver() 257 MockTabStripModelObserver()
243 : empty_(true), 258 : empty_(true),
(...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 ASSERT_EQ(1, observer.GetStateCount()); 2427 ASSERT_EQ(1, observer.GetStateCount());
2413 MockTabStripModelObserver::State s( 2428 MockTabStripModelObserver::State s(
2414 contents2, 1, MockTabStripModelObserver::SELECT); 2429 contents2, 1, MockTabStripModelObserver::SELECT);
2415 s.src_contents = contents2; 2430 s.src_contents = contents2;
2416 s.src_index = 1; 2431 s.src_index = 1;
2417 s.user_gesture = false; 2432 s.user_gesture = false;
2418 EXPECT_TRUE(observer.StateEquals(0, s)); 2433 EXPECT_TRUE(observer.StateEquals(0, s));
2419 strip.RemoveObserver(&observer); 2434 strip.RemoveObserver(&observer);
2420 strip.CloseAllTabs(); 2435 strip.CloseAllTabs();
2421 } 2436 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tab_contents/tab_contents.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698