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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.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/views/tabs/tab_drag_controller_interactive_uitest.h" 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/property_bag.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
12 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
13 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
18 #include "chrome/browser/ui/views/tabs/tab.h" 17 #include "chrome/browser/ui/views/tabs/tab.h"
19 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" 18 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
20 #include "chrome/browser/ui/views/tabs/tab_strip.h" 19 #include "chrome/browser/ui/views/tabs/tab_strip.h"
(...skipping 11 matching lines...) Expand all
32 #include "ui/views/view.h" 31 #include "ui/views/view.h"
33 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
34 33
35 #if defined(USE_ASH) 34 #if defined(USE_ASH)
36 #include "ash/shell.h" 35 #include "ash/shell.h"
37 #include "ui/aura/test/event_generator.h" 36 #include "ui/aura/test/event_generator.h"
38 #endif 37 #endif
39 38
40 namespace test { 39 namespace test {
41 40
41 namespace {
42
43 const char kTabDragControllerInteractiveUITestUserDataKey[] =
44 "TabDragControllerInteractiveUITestUserData";
45
46 class TabDragControllerInteractiveUITestUserData
47 : public base::SupportsUserData::Data {
48 public:
49 explicit TabDragControllerInteractiveUITestUserData(int id) : id_(id) {}
50 virtual ~TabDragControllerInteractiveUITestUserData() {}
51 int id() { return id_; }
52
53 private:
54 int id_;
55 };
56
57 } // namespace
58
42 class QuitDraggingObserver : public content::NotificationObserver { 59 class QuitDraggingObserver : public content::NotificationObserver {
43 public: 60 public:
44 QuitDraggingObserver() { 61 QuitDraggingObserver() {
45 registrar_.Add(this, chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, 62 registrar_.Add(this, chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE,
46 content::NotificationService::AllSources()); 63 content::NotificationService::AllSources());
47 } 64 }
48 65
49 virtual void Observe(int type, 66 virtual void Observe(int type,
50 const content::NotificationSource& source, 67 const content::NotificationSource& source,
51 const content::NotificationDetails& details) OVERRIDE { 68 const content::NotificationDetails& details) OVERRIDE {
52 DCHECK_EQ(chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, type); 69 DCHECK_EQ(chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, type);
53 MessageLoopForUI::current()->Quit(); 70 MessageLoopForUI::current()->Quit();
54 delete this; 71 delete this;
55 } 72 }
56 73
57 private: 74 private:
58 virtual ~QuitDraggingObserver() {} 75 virtual ~QuitDraggingObserver() {}
59 76
60 content::NotificationRegistrar registrar_; 77 content::NotificationRegistrar registrar_;
61 78
62 DISALLOW_COPY_AND_ASSIGN(QuitDraggingObserver); 79 DISALLOW_COPY_AND_ASSIGN(QuitDraggingObserver);
63 }; 80 };
64 81
65 gfx::Point GetCenterInScreenCoordinates(const views::View* view) { 82 gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
66 gfx::Point center(view->width() / 2, view->height() / 2); 83 gfx::Point center(view->width() / 2, view->height() / 2);
67 views::View::ConvertPointToScreen(view, &center); 84 views::View::ConvertPointToScreen(view, &center);
68 return center; 85 return center;
69 } 86 }
70 87
71 base::PropertyAccessor<int>* id_accessor() {
72 static base::PropertyAccessor<int>* accessor = NULL;
73 if (!accessor)
74 accessor = new base::PropertyAccessor<int>;
75 return accessor;
76 }
77
78 void SetID(content::WebContents* tab_contents, int id) { 88 void SetID(content::WebContents* tab_contents, int id) {
79 id_accessor()->SetProperty(tab_contents->GetPropertyBag(), id); 89 tab_contents->SetUserData(&kTabDragControllerInteractiveUITestUserDataKey,
90 new TabDragControllerInteractiveUITestUserData(id));
80 } 91 }
81 92
82 void ResetIDs(TabStripModel* model, int start) { 93 void ResetIDs(TabStripModel* model, int start) {
83 for (int i = 0; i < model->count(); ++i) 94 for (int i = 0; i < model->count(); ++i)
84 SetID(model->GetTabContentsAt(i)->web_contents(), start + i); 95 SetID(model->GetTabContentsAt(i)->web_contents(), start + i);
85 } 96 }
86 97
87 std::string IDString(TabStripModel* model) { 98 std::string IDString(TabStripModel* model) {
88 std::string result; 99 std::string result;
89 for (int i = 0; i < model->count(); ++i) { 100 for (int i = 0; i < model->count(); ++i) {
90 if (i != 0) 101 if (i != 0)
91 result += " "; 102 result += " ";
92 int* id_value = id_accessor()->GetProperty( 103 content::WebContents* contents = model->GetTabContentsAt(i)->web_contents();
93 model->GetTabContentsAt(i)->web_contents()->GetPropertyBag()); 104 TabDragControllerInteractiveUITestUserData* user_data =
94 if (id_value) 105 static_cast<TabDragControllerInteractiveUITestUserData*>(
95 result += base::IntToString(*id_value); 106 contents->GetUserData(
107 &kTabDragControllerInteractiveUITestUserDataKey));
108 if (user_data)
109 result += base::IntToString(user_data->id());
96 else 110 else
97 result += "?"; 111 result += "?";
98 } 112 }
99 return result; 113 return result;
100 } 114 }
101 115
102 // Creates a listener that quits the message loop when no longer dragging. 116 // Creates a listener that quits the message loop when no longer dragging.
103 void QuitWhenNotDraggingImpl() { 117 void QuitWhenNotDraggingImpl() {
104 new QuitDraggingObserver(); // QuitDraggingObserver deletes itself. 118 new QuitDraggingObserver(); // QuitDraggingObserver deletes itself.
105 } 119 }
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 835
822 #if defined(USE_ASH) 836 #if defined(USE_ASH)
823 INSTANTIATE_TEST_CASE_P(TabDragging, 837 INSTANTIATE_TEST_CASE_P(TabDragging,
824 DetachToBrowserTabDragControllerTest, 838 DetachToBrowserTabDragControllerTest,
825 ::testing::Values("mouse", "touch")); 839 ::testing::Values("mouse", "touch"));
826 #else 840 #else
827 INSTANTIATE_TEST_CASE_P(TabDragging, 841 INSTANTIATE_TEST_CASE_P(TabDragging,
828 DetachToBrowserTabDragControllerTest, 842 DetachToBrowserTabDragControllerTest,
829 ::testing::Values("mouse")); 843 ::testing::Values("mouse"));
830 #endif 844 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698