Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 154 |
| 155 scoped_ptr<base::ListValue> disabled_list(new base::ListValue); | 155 scoped_ptr<base::ListValue> disabled_list(new base::ListValue); |
| 156 for (size_t i = 0; i < disabled_features.size(); ++i) | 156 for (size_t i = 0; i < disabled_features.size(); ++i) |
| 157 disabled_list->AppendString(disabled_features[i]); | 157 disabled_list->AppendString(disabled_features[i]); |
| 158 test_arg.Set(kDisabledFeaturesKey, disabled_list.release()); | 158 test_arg.Set(kDisabledFeaturesKey, disabled_list.release()); |
| 159 | 159 |
| 160 return base::JSONWriter::Write(&test_arg, result); | 160 return base::JSONWriter::Write(&test_arg, result); |
| 161 } | 161 } |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 // Disabled now as this test is being flaky, see http://crbug.com/384266. | 164 INSTANTIATE_TEST_CASE_P(AccessibilityFeatureaApiTestInstantiatePermission, |
| 165 INSTANTIATE_TEST_CASE_P( | 165 AccessibilityFeaturesApiTest, |
| 166 DISABLED_AccessibilityFeatureaApiTestInstantiatePermission, | 166 testing::Bool()); |
| 167 AccessibilityFeaturesApiTest, | |
| 168 testing::Bool()); | |
| 169 | 167 |
| 170 // Tests that an extension with read permission can read accessibility features | 168 // Tests that an extension with read permission can read accessibility features |
| 171 // state, while an extension that doesn't have the permission cannot. | 169 // state, while an extension that doesn't have the permission cannot. |
| 172 IN_PROC_BROWSER_TEST_P(AccessibilityFeaturesApiTest, Get) { | 170 IN_PROC_BROWSER_TEST_P(AccessibilityFeaturesApiTest, Get) { |
| 171 // WARNING: Make sure that spoken feedback is not among enabled_features | |
| 172 // (see |Set| test for the reason). | |
| 173 std::vector<std::string> enabled_features; | 173 std::vector<std::string> enabled_features; |
| 174 enabled_features.push_back("largeCursor"); | 174 enabled_features.push_back("largeCursor"); |
| 175 enabled_features.push_back("stickyKeys"); | 175 enabled_features.push_back("stickyKeys"); |
| 176 enabled_features.push_back("highContrast"); | 176 enabled_features.push_back("highContrast"); |
| 177 | 177 |
| 178 std::vector<std::string> disabled_features; | 178 std::vector<std::string> disabled_features; |
| 179 disabled_features.push_back("spokenFeedback"); | 179 disabled_features.push_back("spokenFeedback"); |
| 180 disabled_features.push_back("screenMagnifier"); | 180 disabled_features.push_back("screenMagnifier"); |
| 181 disabled_features.push_back("autoclick"); | 181 disabled_features.push_back("autoclick"); |
| 182 disabled_features.push_back("virtualKeyboard"); | 182 disabled_features.push_back("virtualKeyboard"); |
| 183 | 183 |
| 184 ASSERT_TRUE( | 184 ASSERT_TRUE( |
| 185 InitPrefServiceForTest(GetPrefs(), enabled_features, disabled_features)); | 185 InitPrefServiceForTest(GetPrefs(), enabled_features, disabled_features)); |
| 186 | 186 |
| 187 std::string test_arg; | 187 std::string test_arg; |
| 188 ASSERT_TRUE(GenerateTestArg( | 188 ASSERT_TRUE(GenerateTestArg( |
| 189 "getterTest", enabled_features, disabled_features, &test_arg)); | 189 "getterTest", enabled_features, disabled_features, &test_arg)); |
| 190 EXPECT_TRUE( | 190 EXPECT_TRUE( |
| 191 RunPlatformAppTestWithArg(GetTestExtensionPath(), test_arg.c_str())); | 191 RunPlatformAppTestWithArg(GetTestExtensionPath(), test_arg.c_str())) |
| 192 << message_; | |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Tests that an extension with modify permission can modify accessibility | 195 // Tests that an extension with modify permission can modify accessibility |
| 195 // features, while an extension that doesn't have the permission can't. | 196 // features, while an extension that doesn't have the permission can't. |
| 196 IN_PROC_BROWSER_TEST_P(AccessibilityFeaturesApiTest, Set) { | 197 IN_PROC_BROWSER_TEST_P(AccessibilityFeaturesApiTest, Set) { |
| 198 // WARNING: Make sure that spoken feedback does not get enabled at this point | |
| 199 // (before the test app is loaded), as that may break the test: | |
| 200 // |RunPlatformAppTestWithArg| waits for the test extension to load by | |
| 201 // waiting for EXTENSION_LOADED notification to be observed. It also assumes | |
| 202 // that there is only one extension being loaded during this time (it finishes | |
| 203 // when the first notification is seen). Enabling spoken feedback here would | |
| 204 // break this assumption as it would induce loading of ChromeVox extension. | |
| 197 std::vector<std::string> enabled_features; | 205 std::vector<std::string> enabled_features; |
| 198 enabled_features.push_back("spokenFeedback"); | |
| 199 enabled_features.push_back("stickyKeys"); | 206 enabled_features.push_back("stickyKeys"); |
| 200 enabled_features.push_back("autoclick"); | 207 enabled_features.push_back("autoclick"); |
| 201 enabled_features.push_back("virtualKeyboard"); | 208 enabled_features.push_back("virtualKeyboard"); |
| 202 | 209 |
| 203 std::vector<std::string> disabled_features; | 210 std::vector<std::string> disabled_features; |
| 211 disabled_features.push_back("spokenFeedback"); | |
| 204 disabled_features.push_back("largeCursor"); | 212 disabled_features.push_back("largeCursor"); |
| 205 disabled_features.push_back("highContrast"); | 213 disabled_features.push_back("highContrast"); |
| 206 disabled_features.push_back("screenMagnifier"); | 214 disabled_features.push_back("screenMagnifier"); |
| 207 | 215 |
| 208 ASSERT_TRUE( | 216 ASSERT_TRUE( |
| 209 InitPrefServiceForTest(GetPrefs(), enabled_features, disabled_features)); | 217 InitPrefServiceForTest(GetPrefs(), enabled_features, disabled_features)); |
| 210 | 218 |
| 211 std::string test_arg; | 219 std::string test_arg; |
| 212 ASSERT_TRUE(GenerateTestArg( | 220 ASSERT_TRUE(GenerateTestArg( |
| 213 "setterTest", enabled_features, disabled_features, &test_arg)); | 221 "setterTest", enabled_features, disabled_features, &test_arg)); |
| 214 | 222 |
| 215 // The test extension attempts to flip all feature values. | 223 // The test extension attempts to flip all feature values. |
| 216 ASSERT_TRUE( | 224 ASSERT_TRUE( |
| 217 RunPlatformAppTestWithArg(GetTestExtensionPath(), test_arg.c_str())); | 225 RunPlatformAppTestWithArg(GetTestExtensionPath(), test_arg.c_str())) |
| 226 << message_; | |
| 218 | 227 |
| 219 // The test tries to flip the feature states. | 228 // The test tries to flip the feature states. |
| 220 if (ShouldModifyingFeatureSucceed()) { | 229 if (ShouldModifyingFeatureSucceed()) { |
| 221 VerifyPrefServiceState(GetPrefs(), disabled_features, enabled_features); | 230 VerifyPrefServiceState(GetPrefs(), disabled_features, enabled_features); |
| 222 } else { | 231 } else { |
| 223 VerifyPrefServiceState(GetPrefs(), enabled_features, disabled_features); | 232 VerifyPrefServiceState(GetPrefs(), enabled_features, disabled_features); |
| 224 } | 233 } |
| 225 } | 234 } |
| 226 | 235 |
| 227 // Tests that an extension with read permission is notified when accessibility | 236 // Tests that an extension with read permission is notified when accessibility |
| 228 // features change. | 237 // features change. |
| 229 IN_PROC_BROWSER_TEST_F(AccessibilityFeaturesApiTest, ObserveFeatures) { | 238 IN_PROC_BROWSER_TEST_F(AccessibilityFeaturesApiTest, ObserveFeatures) { |
| 239 // WARNING: Make sure that spoken feedback is not among enabled_features | |
| 240 // (see |Set| test for the reason). | |
| 230 std::vector<std::string> enabled_features; | 241 std::vector<std::string> enabled_features; |
| 231 enabled_features.push_back("largeCursor"); | 242 enabled_features.push_back("largeCursor"); |
| 232 enabled_features.push_back("stickyKeys"); | 243 enabled_features.push_back("stickyKeys"); |
| 233 enabled_features.push_back("highContrast"); | 244 enabled_features.push_back("highContrast"); |
| 234 | 245 |
| 235 std::vector<std::string> disabled_features; | 246 std::vector<std::string> disabled_features; |
| 236 disabled_features.push_back("screenMagnifier"); | 247 disabled_features.push_back("screenMagnifier"); |
| 237 | 248 |
| 238 ASSERT_TRUE( | 249 ASSERT_TRUE( |
| 239 InitPrefServiceForTest(GetPrefs(), enabled_features, disabled_features)); | 250 InitPrefServiceForTest(GetPrefs(), enabled_features, disabled_features)); |
| 240 | 251 |
| 241 std::string test_arg; | 252 std::string test_arg; |
| 242 ASSERT_TRUE(GenerateTestArg( | 253 ASSERT_TRUE(GenerateTestArg( |
| 243 "observerTest", enabled_features, disabled_features, &test_arg)); | 254 "observerTest", enabled_features, disabled_features, &test_arg)); |
| 244 | 255 |
| 245 // The test extension is supposed to report result twice when runnign this | 256 // The test extension is supposed to report result twice when runnign this |
| 246 // test. First time when in initializes it's feature listeners, and second | 257 // test. First time when in initializes it's feature listeners, and second |
| 247 // time, when gets all expected events. This is done so the extension is | 258 // time, when gets all expected events. This is done so the extension is |
| 248 // running when the accessibility features are flipped; oterwise, the | 259 // running when the accessibility features are flipped; oterwise, the |
| 249 // extension may not see events. | 260 // extension may not see events. |
| 250 ASSERT_TRUE(RunPlatformAppTestWithArg(kTestExtensionPathReadPermission, | 261 ASSERT_TRUE(RunPlatformAppTestWithArg(kTestExtensionPathReadPermission, |
| 251 test_arg.c_str())); | 262 test_arg.c_str())) |
| 263 << message_; | |
|
Peter Lundblad
2014/06/18 02:37:03
nit: would this line fit on the previous one?
tbarzic
2014/06/18 03:07:36
It probably would, but I find it more readable thi
| |
| 252 | 264 |
| 253 // This should flip all features. | 265 // This should flip all features. |
| 254 ASSERT_TRUE( | 266 ASSERT_TRUE( |
| 255 InitPrefServiceForTest(GetPrefs(), disabled_features, enabled_features)); | 267 InitPrefServiceForTest(GetPrefs(), disabled_features, enabled_features)); |
| 256 | 268 |
| 257 // Catch the second result notification sent by the test extension. | 269 // Catch the second result notification sent by the test extension. |
| 258 ResultCatcher result_catcher; | 270 ResultCatcher result_catcher; |
| 259 ASSERT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); | 271 ASSERT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); |
| 260 } | 272 } |
| 261 | 273 |
| 262 } // namespace | 274 } // namespace |
| 263 | 275 |
| 264 } // namespace extensions | 276 } // namespace extensions |
| OLD | NEW |