OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_pref_value_map.h" | 9 #include "chrome/browser/extensions/extension_pref_value_map.h" |
10 #include "chrome/common/pref_store_observer_mock.h" | 10 #include "chrome/common/pref_store_observer_mock.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 epvm_.RegisterExtension(kExt1, CreateTime(10), true); | 274 epvm_.RegisterExtension(kExt1, CreateTime(10), true); |
275 | 275 |
276 epvm_.SetExtensionPref(kExt1, kPref1, kRegular, CreateVal("val1")); | 276 epvm_.SetExtensionPref(kExt1, kPref1, kRegular, CreateVal("val1")); |
277 epvm_.SetExtensionState(kExt1, false); | 277 epvm_.SetExtensionState(kExt1, false); |
278 epvm_.SetExtensionState(kExt1, true); | 278 epvm_.SetExtensionState(kExt1, true); |
279 EXPECT_EQ("val1", GetValue(kPref1, false)); | 279 EXPECT_EQ("val1", GetValue(kPref1, false)); |
280 } | 280 } |
281 | 281 |
282 struct OverrideIncognitoTestCase { | 282 struct OverrideIncognitoTestCase { |
283 OverrideIncognitoTestCase(int val_ext1_regular, | 283 OverrideIncognitoTestCase(int val_ext1_regular, |
284 int val_ext1_incognito, | 284 int val_ext1_incognito_pers, |
| 285 int val_ext1_incognito_sess, |
285 int val_ext2_regular, | 286 int val_ext2_regular, |
286 int val_ext2_incognito, | 287 int val_ext2_incognito_pers, |
| 288 int val_ext2_incognito_sess, |
287 int effective_value_regular, | 289 int effective_value_regular, |
288 int effective_value_incognito) | 290 int effective_value_incognito) |
289 : val_ext1_regular_(val_ext1_regular), | 291 : val_ext1_regular_(val_ext1_regular), |
290 val_ext1_incognito_(val_ext1_incognito), | 292 val_ext1_incognito_pers_(val_ext1_incognito_pers), |
| 293 val_ext1_incognito_sess_(val_ext1_incognito_sess), |
291 val_ext2_regular_(val_ext2_regular), | 294 val_ext2_regular_(val_ext2_regular), |
292 val_ext2_incognito_(val_ext2_incognito), | 295 val_ext2_incognito_pers_(val_ext2_incognito_pers), |
| 296 val_ext2_incognito_sess_(val_ext2_incognito_sess), |
293 effective_value_regular_(effective_value_regular), | 297 effective_value_regular_(effective_value_regular), |
294 effective_value_incognito_(effective_value_incognito) {} | 298 effective_value_incognito_(effective_value_incognito) {} |
295 | 299 |
| 300 // pers. = persistent |
| 301 // sess. = session only |
296 int val_ext1_regular_; // pref value of extension 1 | 302 int val_ext1_regular_; // pref value of extension 1 |
297 int val_ext1_incognito_; // pref value of extension 1 incognito | 303 int val_ext1_incognito_pers_; // pref value of extension 1 incognito pers. |
| 304 int val_ext1_incognito_sess_; // pref value of extension 1 incognito sess. |
298 int val_ext2_regular_; // pref value of extension 2 | 305 int val_ext2_regular_; // pref value of extension 2 |
299 int val_ext2_incognito_; // pref value of extension 2 incognito | 306 int val_ext2_incognito_pers_; // pref value of extension 2 incognito pers. |
| 307 int val_ext2_incognito_sess_; // pref value of extension 2 incognito sess. |
300 int effective_value_regular_; // desired winner regular | 308 int effective_value_regular_; // desired winner regular |
301 int effective_value_incognito_; // desired winner incognito | 309 int effective_value_incognito_; // desired winner incognito |
302 }; | 310 }; |
303 | 311 |
304 class ExtensionPrefValueMapTestIncognitoTests | 312 class ExtensionPrefValueMapTestIncognitoTests |
305 : public ExtensionPrefValueMapTestBase< | 313 : public ExtensionPrefValueMapTestBase< |
306 testing::TestWithParam<OverrideIncognitoTestCase> > { | 314 testing::TestWithParam<OverrideIncognitoTestCase> > { |
307 }; | 315 }; |
308 | 316 |
309 TEST_P(ExtensionPrefValueMapTestIncognitoTests, OverrideIncognito) { | 317 TEST_P(ExtensionPrefValueMapTestIncognitoTests, OverrideIncognito) { |
310 using namespace extension_prefs_scope; | 318 using namespace extension_prefs_scope; |
311 OverrideIncognitoTestCase test = GetParam(); | 319 OverrideIncognitoTestCase test = GetParam(); |
312 const char* strings[] = { | 320 const char* strings[] = { |
313 "undefined", | 321 "undefined", |
314 "val1", | 322 "val1", |
315 "val2", | 323 "val2", |
316 "val3", | 324 "val3", |
317 "val4" | 325 "val4", |
| 326 "val5", |
| 327 "val6" |
318 }; | 328 }; |
319 | 329 |
320 epvm_.RegisterExtension(kExt1, CreateTime(10), true); | 330 epvm_.RegisterExtension(kExt1, CreateTime(10), true); |
321 epvm_.RegisterExtension(kExt2, CreateTime(20), true); | 331 epvm_.RegisterExtension(kExt2, CreateTime(20), true); |
322 if (test.val_ext1_regular_) { | 332 if (test.val_ext1_regular_) { |
323 epvm_.SetExtensionPref(kExt1, kPref1, kRegular, | 333 epvm_.SetExtensionPref(kExt1, kPref1, kRegular, |
324 CreateVal(strings[test.val_ext1_regular_])); | 334 CreateVal(strings[test.val_ext1_regular_])); |
325 } | 335 } |
326 if (test.val_ext1_incognito_) { | 336 if (test.val_ext1_incognito_pers_) { |
327 epvm_.SetExtensionPref(kExt1, kPref1, kIncognitoPersistent, | 337 epvm_.SetExtensionPref(kExt1, kPref1, kIncognitoPersistent, |
328 CreateVal(strings[test.val_ext1_incognito_])); | 338 CreateVal(strings[test.val_ext1_incognito_pers_])); |
| 339 } |
| 340 if (test.val_ext1_incognito_sess_) { |
| 341 epvm_.SetExtensionPref(kExt1, kPref1, kIncognitoSessionOnly, |
| 342 CreateVal(strings[test.val_ext1_incognito_sess_])); |
329 } | 343 } |
330 if (test.val_ext2_regular_) { | 344 if (test.val_ext2_regular_) { |
331 epvm_.SetExtensionPref(kExt2, kPref1, kRegular, | 345 epvm_.SetExtensionPref(kExt2, kPref1, kRegular, |
332 CreateVal(strings[test.val_ext2_regular_])); | 346 CreateVal(strings[test.val_ext2_regular_])); |
333 } | 347 } |
334 if (test.val_ext2_incognito_) { | 348 if (test.val_ext2_incognito_pers_) { |
335 epvm_.SetExtensionPref(kExt2, kPref1, kIncognitoPersistent, | 349 epvm_.SetExtensionPref(kExt2, kPref1, kIncognitoPersistent, |
336 CreateVal(strings[test.val_ext2_incognito_])); | 350 CreateVal(strings[test.val_ext2_incognito_pers_])); |
| 351 } |
| 352 if (test.val_ext2_incognito_sess_) { |
| 353 epvm_.SetExtensionPref(kExt2, kPref1, kIncognitoSessionOnly, |
| 354 CreateVal(strings[test.val_ext2_incognito_sess_])); |
337 } | 355 } |
338 std::string actual; | 356 std::string actual; |
339 EXPECT_EQ(strings[test.effective_value_regular_], GetValue(kPref1, false)); | 357 EXPECT_EQ(strings[test.effective_value_regular_], GetValue(kPref1, false)); |
340 EXPECT_EQ(strings[test.effective_value_incognito_], GetValue(kPref1, true)); | 358 EXPECT_EQ(strings[test.effective_value_incognito_], GetValue(kPref1, true)); |
341 epvm_.UnregisterExtension(kExt1); | 359 epvm_.UnregisterExtension(kExt1); |
342 epvm_.UnregisterExtension(kExt2); | 360 epvm_.UnregisterExtension(kExt2); |
343 } | 361 } |
344 | 362 |
345 INSTANTIATE_TEST_CASE_P( | 363 INSTANTIATE_TEST_CASE_P( |
346 ExtensionPrefValueMapTestIncognitoTestsInstance, | 364 ExtensionPrefValueMapTestIncognitoTestsInstance, |
347 ExtensionPrefValueMapTestIncognitoTests, | 365 ExtensionPrefValueMapTestIncognitoTests, |
348 testing::Values( | 366 testing::Values( |
349 // e.g. (1, 0, 0, 4, 1, 4), means: | 367 // e.g. (1, 0, 0, 0, 4, 0, 1, 4), means: |
350 // ext1 regular is set to "val1", ext2 incognito is set to "val4" | 368 // ext1 regular is set to "val1", ext2 incognito persistent is set to |
| 369 // "val4" |
351 // --> the winning regular value is "val1", the winning incognito | 370 // --> the winning regular value is "val1", the winning incognito |
352 // value is "val4". | 371 // value is "val4". |
353 OverrideIncognitoTestCase(1, 0, 0, 0, 1, 1), | 372 OverrideIncognitoTestCase(1, 0, 0, 0, 0, 0, 1, 1), |
354 OverrideIncognitoTestCase(1, 2, 0, 0, 1, 2), | 373 OverrideIncognitoTestCase(1, 2, 0, 0, 0, 0, 1, 2), |
355 OverrideIncognitoTestCase(1, 0, 3, 0, 3, 3), | 374 OverrideIncognitoTestCase(1, 0, 3, 0, 0, 0, 1, 3), |
356 OverrideIncognitoTestCase(1, 0, 0, 4, 1, 4), | 375 OverrideIncognitoTestCase(1, 0, 0, 4, 0, 0, 4, 4), |
357 // The last 3 in the following line is intentional! | 376 OverrideIncognitoTestCase(1, 0, 0, 0, 5, 0, 1, 5), |
358 OverrideIncognitoTestCase(1, 2, 3, 0, 3, 3), | 377 OverrideIncognitoTestCase(1, 0, 0, 0, 0, 6, 1, 6), |
359 OverrideIncognitoTestCase(1, 2, 0, 4, 1, 4), | 378 // The last 4 in the following line is intentional! |
360 OverrideIncognitoTestCase(1, 2, 3, 4, 3, 4))); | 379 OverrideIncognitoTestCase(1, 2, 0, 4, 0, 0, 4, 4), |
| 380 OverrideIncognitoTestCase(1, 2, 0, 0, 5, 0, 1, 5), |
| 381 OverrideIncognitoTestCase(1, 2, 3, 0, 5, 0, 1, 5), |
| 382 OverrideIncognitoTestCase(1, 2, 0, 3, 5, 0, 3, 5), |
| 383 OverrideIncognitoTestCase(1, 2, 0, 3, 5, 6, 3, 6))); |
OLD | NEW |