| 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 <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 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 textfield->SetText(kText); | 1037 textfield->SetText(kText); |
| 1038 EXPECT_EQ(kText, textfield->text()); | 1038 EXPECT_EQ(kText, textfield->text()); |
| 1039 textfield->AppendText(kExtraText); | 1039 textfield->AppendText(kExtraText); |
| 1040 EXPECT_EQ(kText + kExtraText, textfield->text()); | 1040 EXPECT_EQ(kText + kExtraText, textfield->text()); |
| 1041 textfield->SetText(string16()); | 1041 textfield->SetText(string16()); |
| 1042 EXPECT_EQ(kEmptyString, textfield->text()); | 1042 EXPECT_EQ(kEmptyString, textfield->text()); |
| 1043 | 1043 |
| 1044 // Test selection related methods. | 1044 // Test selection related methods. |
| 1045 textfield->SetText(kText); | 1045 textfield->SetText(kText); |
| 1046 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); | 1046 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); |
| 1047 textfield->SelectAll(); | 1047 textfield->SelectAll(false); |
| 1048 EXPECT_EQ(kText, textfield->text()); | 1048 EXPECT_EQ(kText, textfield->text()); |
| 1049 textfield->ClearSelection(); | 1049 textfield->ClearSelection(); |
| 1050 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); | 1050 EXPECT_EQ(kEmptyString, textfield->GetSelectedText()); |
| 1051 | 1051 |
| 1052 widget->CloseNow(); | 1052 widget->CloseNow(); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 #if defined(OS_WIN) && !defined(USE_AURA) | 1055 #if defined(OS_WIN) && !defined(USE_AURA) |
| 1056 | 1056 |
| 1057 // Tests that the Textfield view respond appropiately to cut/copy/paste. | 1057 // Tests that the Textfield view respond appropiately to cut/copy/paste. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1078 root_view->AddChildView(password); | 1078 root_view->AddChildView(password); |
| 1079 | 1079 |
| 1080 normal->SetText(kNormalText); | 1080 normal->SetText(kNormalText); |
| 1081 read_only->SetText(kReadOnlyText); | 1081 read_only->SetText(kReadOnlyText); |
| 1082 password->SetText(kPasswordText); | 1082 password->SetText(kPasswordText); |
| 1083 | 1083 |
| 1084 // | 1084 // |
| 1085 // Test cut. | 1085 // Test cut. |
| 1086 // | 1086 // |
| 1087 ASSERT_TRUE(normal->GetTestingHandle()); | 1087 ASSERT_TRUE(normal->GetTestingHandle()); |
| 1088 normal->SelectAll(); | 1088 normal->SelectAll(false); |
| 1089 ::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0); | 1089 ::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0); |
| 1090 | 1090 |
| 1091 string16 result; | 1091 string16 result; |
| 1092 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 1092 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 1093 EXPECT_EQ(kNormalText, result); | 1093 EXPECT_EQ(kNormalText, result); |
| 1094 normal->SetText(kNormalText); // Let's revert to the original content. | 1094 normal->SetText(kNormalText); // Let's revert to the original content. |
| 1095 | 1095 |
| 1096 ASSERT_TRUE(read_only->GetTestingHandle()); | 1096 ASSERT_TRUE(read_only->GetTestingHandle()); |
| 1097 read_only->SelectAll(); | 1097 read_only->SelectAll(false); |
| 1098 ::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0); | 1098 ::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0); |
| 1099 result.clear(); | 1099 result.clear(); |
| 1100 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 1100 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 1101 // Cut should have failed, so the clipboard content should not have changed. | 1101 // Cut should have failed, so the clipboard content should not have changed. |
| 1102 EXPECT_EQ(kNormalText, result); | 1102 EXPECT_EQ(kNormalText, result); |
| 1103 | 1103 |
| 1104 ASSERT_TRUE(password->GetTestingHandle()); | 1104 ASSERT_TRUE(password->GetTestingHandle()); |
| 1105 password->SelectAll(); | 1105 password->SelectAll(false); |
| 1106 ::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0); | 1106 ::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0); |
| 1107 result.clear(); | 1107 result.clear(); |
| 1108 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 1108 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 1109 // Cut should have failed, so the clipboard content should not have changed. | 1109 // Cut should have failed, so the clipboard content should not have changed. |
| 1110 EXPECT_EQ(kNormalText, result); | 1110 EXPECT_EQ(kNormalText, result); |
| 1111 | 1111 |
| 1112 // | 1112 // |
| 1113 // Test copy. | 1113 // Test copy. |
| 1114 // | 1114 // |
| 1115 | 1115 |
| 1116 // Let's start with read_only as the clipboard already contains the content | 1116 // Let's start with read_only as the clipboard already contains the content |
| 1117 // of normal. | 1117 // of normal. |
| 1118 read_only->SelectAll(); | 1118 read_only->SelectAll(false); |
| 1119 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); | 1119 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); |
| 1120 result.clear(); | 1120 result.clear(); |
| 1121 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 1121 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 1122 EXPECT_EQ(kReadOnlyText, result); | 1122 EXPECT_EQ(kReadOnlyText, result); |
| 1123 | 1123 |
| 1124 normal->SelectAll(); | 1124 normal->SelectAll(false); |
| 1125 ::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0); | 1125 ::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0); |
| 1126 result.clear(); | 1126 result.clear(); |
| 1127 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 1127 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 1128 EXPECT_EQ(kNormalText, result); | 1128 EXPECT_EQ(kNormalText, result); |
| 1129 | 1129 |
| 1130 password->SelectAll(); | 1130 password->SelectAll(false); |
| 1131 ::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0); | 1131 ::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0); |
| 1132 result.clear(); | 1132 result.clear(); |
| 1133 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 1133 clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 1134 // We don't let you copy from an obscured field, clipboard should not have | 1134 // We don't let you copy from an obscured field, clipboard should not have |
| 1135 // changed. | 1135 // changed. |
| 1136 EXPECT_EQ(kNormalText, result); | 1136 EXPECT_EQ(kNormalText, result); |
| 1137 | 1137 |
| 1138 // | 1138 // |
| 1139 // Test Paste. | 1139 // Test Paste. |
| 1140 // | 1140 // |
| 1141 // Note that we use GetWindowText instead of Textfield::GetText below as the | 1141 // Note that we use GetWindowText instead of Textfield::GetText below as the |
| 1142 // text in the Textfield class is synced to the text of the HWND on | 1142 // text in the Textfield class is synced to the text of the HWND on |
| 1143 // WM_KEYDOWN messages that we are not simulating here. | 1143 // WM_KEYDOWN messages that we are not simulating here. |
| 1144 | 1144 |
| 1145 // Attempting to copy kNormalText in a read-only text-field should fail. | 1145 // Attempting to copy kNormalText in a read-only text-field should fail. |
| 1146 read_only->SelectAll(); | 1146 read_only->SelectAll(false); |
| 1147 ::SendMessage(read_only->GetTestingHandle(), WM_KEYDOWN, 0, 0); | 1147 ::SendMessage(read_only->GetTestingHandle(), WM_KEYDOWN, 0, 0); |
| 1148 wchar_t buffer[1024] = { 0 }; | 1148 wchar_t buffer[1024] = { 0 }; |
| 1149 ::GetWindowText(read_only->GetTestingHandle(), buffer, 1024); | 1149 ::GetWindowText(read_only->GetTestingHandle(), buffer, 1024); |
| 1150 EXPECT_EQ(kReadOnlyText, string16(buffer)); | 1150 EXPECT_EQ(kReadOnlyText, string16(buffer)); |
| 1151 | 1151 |
| 1152 password->SelectAll(); | 1152 password->SelectAll(false); |
| 1153 ::SendMessage(password->GetTestingHandle(), WM_PASTE, 0, 0); | 1153 ::SendMessage(password->GetTestingHandle(), WM_PASTE, 0, 0); |
| 1154 ::GetWindowText(password->GetTestingHandle(), buffer, 1024); | 1154 ::GetWindowText(password->GetTestingHandle(), buffer, 1024); |
| 1155 EXPECT_EQ(kNormalText, string16(buffer)); | 1155 EXPECT_EQ(kNormalText, string16(buffer)); |
| 1156 | 1156 |
| 1157 // Copy from read_only so the string we are pasting is not the same as the | 1157 // Copy from read_only so the string we are pasting is not the same as the |
| 1158 // current one. | 1158 // current one. |
| 1159 read_only->SelectAll(); | 1159 read_only->SelectAll(false); |
| 1160 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); | 1160 ::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0); |
| 1161 normal->SelectAll(); | 1161 normal->SelectAll(false); |
| 1162 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); | 1162 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); |
| 1163 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); | 1163 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); |
| 1164 EXPECT_EQ(kReadOnlyText, string16(buffer)); | 1164 EXPECT_EQ(kReadOnlyText, string16(buffer)); |
| 1165 widget->CloseNow(); | 1165 widget->CloseNow(); |
| 1166 } | 1166 } |
| 1167 #endif | 1167 #endif |
| 1168 | 1168 |
| 1169 //////////////////////////////////////////////////////////////////////////////// | 1169 //////////////////////////////////////////////////////////////////////////////// |
| 1170 // Accelerators | 1170 // Accelerators |
| 1171 //////////////////////////////////////////////////////////////////////////////// | 1171 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 2062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3234 // Set to non default value. | 3234 // Set to non default value. |
| 3235 v->layer()->set_scale_content(false); | 3235 v->layer()->set_scale_content(false); |
| 3236 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); | 3236 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); |
| 3237 ui::Layer* new_layer = v->layer(); | 3237 ui::Layer* new_layer = v->layer(); |
| 3238 EXPECT_EQ(false, new_layer->scale_content()); | 3238 EXPECT_EQ(false, new_layer->scale_content()); |
| 3239 } | 3239 } |
| 3240 | 3240 |
| 3241 #endif // USE_AURA | 3241 #endif // USE_AURA |
| 3242 | 3242 |
| 3243 } // namespace views | 3243 } // namespace views |
| OLD | NEW |