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

Side by Side Diff: ui/views/view_unittest.cc

Issue 10911074: Change how ui::Clipboard is accessed so there's only one per thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix various windows compile failures. Created 8 years, 3 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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1161
1162 widget->CloseNow(); 1162 widget->CloseNow();
1163 } 1163 }
1164 1164
1165 TEST_F(ViewTest, Textfield) { 1165 TEST_F(ViewTest, Textfield) {
1166 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " 1166 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop "
1167 "believing it, doesn't go away."); 1167 "believing it, doesn't go away.");
1168 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); 1168 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!");
1169 const string16 kEmptyString; 1169 const string16 kEmptyString;
1170 1170
1171 ui::Clipboard clipboard;
1172
1173 Widget* widget = new Widget; 1171 Widget* widget = new Widget;
1174 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1172 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
1175 params.bounds = gfx::Rect(0, 0, 100, 100); 1173 params.bounds = gfx::Rect(0, 0, 100, 100);
1176 widget->Init(params); 1174 widget->Init(params);
1177 View* root_view = widget->GetRootView(); 1175 View* root_view = widget->GetRootView();
1178 1176
1179 Textfield* textfield = new Textfield(); 1177 Textfield* textfield = new Textfield();
1180 root_view->AddChildView(textfield); 1178 root_view->AddChildView(textfield);
1181 1179
1182 // Test setting, appending text. 1180 // Test setting, appending text.
(...skipping 16 matching lines...) Expand all
1199 } 1197 }
1200 1198
1201 #if defined(OS_WIN) && !defined(USE_AURA) 1199 #if defined(OS_WIN) && !defined(USE_AURA)
1202 1200
1203 // Tests that the Textfield view respond appropiately to cut/copy/paste. 1201 // Tests that the Textfield view respond appropiately to cut/copy/paste.
1204 TEST_F(ViewTest, TextfieldCutCopyPaste) { 1202 TEST_F(ViewTest, TextfieldCutCopyPaste) {
1205 const string16 kNormalText = ASCIIToUTF16("Normal"); 1203 const string16 kNormalText = ASCIIToUTF16("Normal");
1206 const string16 kReadOnlyText = ASCIIToUTF16("Read only"); 1204 const string16 kReadOnlyText = ASCIIToUTF16("Read only");
1207 const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **"); 1205 const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **");
1208 1206
1209 ui::Clipboard clipboard; 1207 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1210 1208
1211 Widget* widget = new Widget; 1209 Widget* widget = new Widget;
1212 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 1210 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
1213 params.bounds = gfx::Rect(0, 0, 100, 100); 1211 params.bounds = gfx::Rect(0, 0, 100, 100);
1214 widget->Init(params); 1212 widget->Init(params);
1215 View* root_view = widget->GetRootView(); 1213 View* root_view = widget->GetRootView();
1216 1214
1217 Textfield* normal = new Textfield(); 1215 Textfield* normal = new Textfield();
1218 Textfield* read_only = new Textfield(); 1216 Textfield* read_only = new Textfield();
1219 read_only->SetReadOnly(true); 1217 read_only->SetReadOnly(true);
1220 Textfield* password = new Textfield(Textfield::STYLE_OBSCURED); 1218 Textfield* password = new Textfield(Textfield::STYLE_OBSCURED);
1221 1219
1222 root_view->AddChildView(normal); 1220 root_view->AddChildView(normal);
1223 root_view->AddChildView(read_only); 1221 root_view->AddChildView(read_only);
1224 root_view->AddChildView(password); 1222 root_view->AddChildView(password);
1225 1223
1226 normal->SetText(kNormalText); 1224 normal->SetText(kNormalText);
1227 read_only->SetText(kReadOnlyText); 1225 read_only->SetText(kReadOnlyText);
1228 password->SetText(kPasswordText); 1226 password->SetText(kPasswordText);
1229 1227
1230 // 1228 //
1231 // Test cut. 1229 // Test cut.
1232 // 1230 //
1233 ASSERT_TRUE(normal->GetTestingHandle()); 1231 ASSERT_TRUE(normal->GetTestingHandle());
1234 normal->SelectAll(false); 1232 normal->SelectAll(false);
1235 ::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0); 1233 ::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0);
1236 1234
1237 string16 result; 1235 string16 result;
1238 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 1236 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
1239 EXPECT_EQ(kNormalText, result); 1237 EXPECT_EQ(kNormalText, result);
1240 normal->SetText(kNormalText); // Let's revert to the original content. 1238 normal->SetText(kNormalText); // Let's revert to the original content.
1241 1239
1242 ASSERT_TRUE(read_only->GetTestingHandle()); 1240 ASSERT_TRUE(read_only->GetTestingHandle());
1243 read_only->SelectAll(false); 1241 read_only->SelectAll(false);
1244 ::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0); 1242 ::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0);
1245 result.clear(); 1243 result.clear();
1246 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 1244 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
1247 // Cut should have failed, so the clipboard content should not have changed. 1245 // Cut should have failed, so the clipboard content should not have changed.
1248 EXPECT_EQ(kNormalText, result); 1246 EXPECT_EQ(kNormalText, result);
1249 1247
1250 ASSERT_TRUE(password->GetTestingHandle()); 1248 ASSERT_TRUE(password->GetTestingHandle());
1251 password->SelectAll(false); 1249 password->SelectAll(false);
1252 ::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0); 1250 ::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0);
1253 result.clear(); 1251 result.clear();
1254 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 1252 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
1255 // Cut should have failed, so the clipboard content should not have changed. 1253 // Cut should have failed, so the clipboard content should not have changed.
1256 EXPECT_EQ(kNormalText, result); 1254 EXPECT_EQ(kNormalText, result);
1257 1255
1258 // 1256 //
1259 // Test copy. 1257 // Test copy.
1260 // 1258 //
1261 1259
1262 // Let's start with read_only as the clipboard already contains the content 1260 // Let's start with read_only as the clipboard already contains the content
1263 // of normal. 1261 // of normal.
1264 read_only->SelectAll(false); 1262 read_only->SelectAll(false);
1265 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); 1263 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0);
1266 result.clear(); 1264 result.clear();
1267 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 1265 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
1268 EXPECT_EQ(kReadOnlyText, result); 1266 EXPECT_EQ(kReadOnlyText, result);
1269 1267
1270 normal->SelectAll(false); 1268 normal->SelectAll(false);
1271 ::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0); 1269 ::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0);
1272 result.clear(); 1270 result.clear();
1273 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 1271 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
1274 EXPECT_EQ(kNormalText, result); 1272 EXPECT_EQ(kNormalText, result);
1275 1273
1276 password->SelectAll(false); 1274 password->SelectAll(false);
1277 ::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0); 1275 ::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0);
1278 result.clear(); 1276 result.clear();
1279 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 1277 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
1280 // We don't let you copy from an obscured field, clipboard should not have 1278 // We don't let you copy from an obscured field, clipboard should not have
1281 // changed. 1279 // changed.
1282 EXPECT_EQ(kNormalText, result); 1280 EXPECT_EQ(kNormalText, result);
1283 1281
1284 // 1282 //
1285 // Test Paste. 1283 // Test Paste.
1286 // 1284 //
1287 // Note that we use GetWindowText instead of Textfield::GetText below as the 1285 // Note that we use GetWindowText instead of Textfield::GetText below as the
1288 // text in the Textfield class is synced to the text of the HWND on 1286 // text in the Textfield class is synced to the text of the HWND on
1289 // WM_KEYDOWN messages that we are not simulating here. 1287 // WM_KEYDOWN messages that we are not simulating here.
(...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after
3382 // Set to non default value. 3380 // Set to non default value.
3383 v->layer()->set_scale_content(false); 3381 v->layer()->set_scale_content(false);
3384 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); 3382 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer());
3385 ui::Layer* new_layer = v->layer(); 3383 ui::Layer* new_layer = v->layer();
3386 EXPECT_FALSE(new_layer->scale_content()); 3384 EXPECT_FALSE(new_layer->scale_content());
3387 } 3385 }
3388 3386
3389 #endif // USE_AURA 3387 #endif // USE_AURA
3390 3388
3391 } // namespace views 3389 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698