OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator.h" | 5 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator.h" |
6 | 6 |
7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #import "base/mac/scoped_nsobject.h" | |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
16 #import "base/test/ios/wait_util.h" | 15 #import "base/test/ios/wait_util.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
19 #include "components/search_engines/template_url.h" | 18 #include "components/search_engines/template_url.h" |
20 #include "components/search_engines/template_url_data.h" | 19 #include "components/search_engines/template_url_data.h" |
21 #include "components/search_engines/template_url_service.h" | 20 #include "components/search_engines/template_url_service.h" |
22 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 21 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
23 #include "ios/chrome/browser/chrome_switches.h" | 22 #include "ios/chrome/browser/chrome_switches.h" |
24 #include "ios/chrome/browser/pref_names.h" | 23 #include "ios/chrome/browser/pref_names.h" |
25 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
26 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 25 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
27 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h" | 26 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_test_util.h" |
28 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 27 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
29 #include "ios/chrome/browser/sync/sync_setup_service_mock.h" | 28 #include "ios/chrome/browser/sync/sync_setup_service_mock.h" |
30 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator+testing.h" | 29 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator+testing.h" |
31 #include "ios/web/public/test/test_web_thread_bundle.h" | 30 #include "ios/web/public/test/test_web_thread_bundle.h" |
32 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
33 #import "testing/gtest_mac.h" | 32 #import "testing/gtest_mac.h" |
34 #include "testing/platform_test.h" | 33 #include "testing/platform_test.h" |
35 #import "third_party/ocmock/OCMock/OCMock.h" | 34 #import "third_party/ocmock/OCMock/OCMock.h" |
36 #include "third_party/ocmock/gtest_support.h" | 35 #include "third_party/ocmock/gtest_support.h" |
37 | 36 |
| 37 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 38 #error "This file requires ARC support." |
| 39 #endif |
| 40 |
38 using testing::Return; | 41 using testing::Return; |
39 | 42 |
40 @interface TestTouchToSearchPermissionsAudience | 43 @interface TestTouchToSearchPermissionsAudience |
41 : NSObject<TouchToSearchPermissionsChangeAudience> | 44 : NSObject<TouchToSearchPermissionsChangeAudience> |
42 @property BOOL updated; | 45 @property BOOL updated; |
43 @end | 46 @end |
44 | 47 |
45 @implementation TestTouchToSearchPermissionsAudience | 48 @implementation TestTouchToSearchPermissionsAudience |
46 @synthesize updated = _updated; | 49 @synthesize updated = _updated; |
47 - (void)touchToSearchPermissionsUpdated { | 50 - (void)touchToSearchPermissionsUpdated { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 TestChromeBrowserState::Builder browserStateBuilder; | 100 TestChromeBrowserState::Builder browserStateBuilder; |
98 browserStateBuilder.AddTestingFactory( | 101 browserStateBuilder.AddTestingFactory( |
99 SyncSetupServiceFactory::GetInstance(), &CreateSyncSetupService); | 102 SyncSetupServiceFactory::GetInstance(), &CreateSyncSetupService); |
100 browserStateBuilder.AddTestingFactory( | 103 browserStateBuilder.AddTestingFactory( |
101 ios::TemplateURLServiceFactory::GetInstance(), | 104 ios::TemplateURLServiceFactory::GetInstance(), |
102 ios::TemplateURLServiceFactory::GetDefaultFactory()); | 105 ios::TemplateURLServiceFactory::GetDefaultFactory()); |
103 browser_state_ = browserStateBuilder.Build(); | 106 browser_state_ = browserStateBuilder.Build(); |
104 template_url_service_ = | 107 template_url_service_ = |
105 ios::TemplateURLServiceFactory::GetForBrowserState(BrowserState()); | 108 ios::TemplateURLServiceFactory::GetForBrowserState(BrowserState()); |
106 template_url_service_->Load(); | 109 template_url_service_->Load(); |
107 tts_permissions_.reset([[TouchToSearchPermissionsMediator alloc] | 110 tts_permissions_ = [[TouchToSearchPermissionsMediator alloc] |
108 initWithBrowserState:BrowserState()]); | 111 initWithBrowserState:BrowserState()]; |
109 } | 112 } |
110 | 113 |
111 ios::ChromeBrowserState* BrowserState() { return browser_state_.get(); } | 114 ios::ChromeBrowserState* BrowserState() { return browser_state_.get(); } |
112 | 115 |
113 web::TestWebThreadBundle thread_bundle_; | 116 web::TestWebThreadBundle thread_bundle_; |
114 std::unique_ptr<TestChromeBrowserState> browser_state_; | 117 std::unique_ptr<TestChromeBrowserState> browser_state_; |
115 base::scoped_nsobject<TouchToSearchPermissionsMediator> tts_permissions_; | 118 TouchToSearchPermissionsMediator* tts_permissions_; |
116 TemplateURLService* template_url_service_; | 119 TemplateURLService* template_url_service_; |
117 }; | 120 }; |
118 | 121 |
119 TEST_F(TouchToSearchPermissionsMediatorTest, PrefStates) { | 122 TEST_F(TouchToSearchPermissionsMediatorTest, PrefStates) { |
120 // Expect empty browser state to have undecided pref value. | 123 // Expect empty browser state to have undecided pref value. |
121 EXPECT_EQ(TouchToSearch::UNDECIDED, [tts_permissions_ preferenceState]); | 124 EXPECT_EQ(TouchToSearch::UNDECIDED, [tts_permissions_ preferenceState]); |
122 | 125 |
123 const struct { | 126 const struct { |
124 const std::string pref_value; | 127 const std::string pref_value; |
125 TouchToSearch::TouchToSearchPreferenceState state; | 128 TouchToSearch::TouchToSearchPreferenceState state; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 [tts_permissions_ canPreloadSearchResults]); | 264 [tts_permissions_ canPreloadSearchResults]); |
262 } | 265 } |
263 } | 266 } |
264 } | 267 } |
265 | 268 |
266 TEST_F(TouchToSearchPermissionsMediatorTest, | 269 TEST_F(TouchToSearchPermissionsMediatorTest, |
267 AreQueriesDisallowedWithoutTemplateService) { | 270 AreQueriesDisallowedWithoutTemplateService) { |
268 TestChromeBrowserState::Builder browserStateBuilder; | 271 TestChromeBrowserState::Builder browserStateBuilder; |
269 std::unique_ptr<TestChromeBrowserState> browser_state( | 272 std::unique_ptr<TestChromeBrowserState> browser_state( |
270 browserStateBuilder.Build()); | 273 browserStateBuilder.Build()); |
271 base::scoped_nsobject<TouchToSearchPermissionsMediator> tts_permissions( | 274 TouchToSearchPermissionsMediator* tts_permissions = |
272 [[TouchToSearchPermissionsMediator alloc] | 275 [[TouchToSearchPermissionsMediator alloc] |
273 initWithBrowserState:browser_state.get()]); | 276 initWithBrowserState:browser_state.get()]; |
274 EXPECT_FALSE([tts_permissions areContextualSearchQueriesSupported]); | 277 EXPECT_FALSE([tts_permissions areContextualSearchQueriesSupported]); |
275 } | 278 } |
276 | 279 |
277 TEST_F(TouchToSearchPermissionsMediatorTest, AreQueriesAllowed) { | 280 TEST_F(TouchToSearchPermissionsMediatorTest, AreQueriesAllowed) { |
278 // The initial default search engine should support contextual search. | 281 // The initial default search engine should support contextual search. |
279 EXPECT_TRUE([tts_permissions_ areContextualSearchQueriesSupported]); | 282 EXPECT_TRUE([tts_permissions_ areContextualSearchQueriesSupported]); |
280 | 283 |
281 // Make a user-defined search engine and set it as the default. | 284 // Make a user-defined search engine and set it as the default. |
282 TemplateURLData data; | 285 TemplateURLData data; |
283 data.SetShortName(base::ASCIIToUTF16("cs-not-supported")); | 286 data.SetShortName(base::ASCIIToUTF16("cs-not-supported")); |
284 | 287 |
285 TemplateURL* newUrl = template_url_service_->Add( | 288 TemplateURL* newUrl = template_url_service_->Add( |
286 std::unique_ptr<TemplateURL>(new TemplateURL(data))); | 289 std::unique_ptr<TemplateURL>(new TemplateURL(data))); |
287 // |template_url_service_| will take ownership of newUrl | 290 // |template_url_service_| will take ownership of newUrl |
288 ASSERT_TRUE(newUrl); | 291 ASSERT_TRUE(newUrl); |
289 template_url_service_->SetUserSelectedDefaultSearchProvider(newUrl); | 292 template_url_service_->SetUserSelectedDefaultSearchProvider(newUrl); |
290 | 293 |
291 // The newly-selected search engine doesn't support contextual search. | 294 // The newly-selected search engine doesn't support contextual search. |
292 EXPECT_FALSE([tts_permissions_ areContextualSearchQueriesSupported]); | 295 EXPECT_FALSE([tts_permissions_ areContextualSearchQueriesSupported]); |
293 } | 296 } |
294 | 297 |
295 TEST_F(TouchToSearchPermissionsMediatorTest, CanEnable) { | 298 TEST_F(TouchToSearchPermissionsMediatorTest, CanEnable) { |
296 base::scoped_nsobject<MockTouchToSearchPermissionsMediator> permissions( | 299 MockTouchToSearchPermissionsMediator* permissions = |
297 [[MockTouchToSearchPermissionsMediator alloc] | 300 [[MockTouchToSearchPermissionsMediator alloc] |
298 initWithBrowserState:BrowserState()]); | 301 initWithBrowserState:BrowserState()]; |
299 | 302 |
300 const struct { | 303 const struct { |
301 BOOL enabled_on_device; | 304 BOOL enabled_on_device; |
302 TouchToSearch::TouchToSearchPreferenceState prefState; | 305 TouchToSearch::TouchToSearchPreferenceState prefState; |
303 BOOL voiceover_enabled; | 306 BOOL voiceover_enabled; |
304 BOOL queries_allowed; | 307 BOOL queries_allowed; |
305 BOOL expect_available; | 308 BOOL expect_available; |
306 } tests[] = { | 309 } tests[] = { |
307 // clang-format off | 310 // clang-format off |
308 // Enabled cases: | 311 // Enabled cases: |
(...skipping 24 matching lines...) Expand all Loading... |
333 {YES, TouchToSearch::UNDECIDED, YES, YES, NO}, | 336 {YES, TouchToSearch::UNDECIDED, YES, YES, NO}, |
334 {YES, TouchToSearch::ENABLED, NO, NO, NO}, | 337 {YES, TouchToSearch::ENABLED, NO, NO, NO}, |
335 {YES, TouchToSearch::ENABLED, YES, NO, NO}, | 338 {YES, TouchToSearch::ENABLED, YES, NO, NO}, |
336 {YES, TouchToSearch::ENABLED, YES, YES, NO}, | 339 {YES, TouchToSearch::ENABLED, YES, YES, NO}, |
337 // clang-format on | 340 // clang-format on |
338 }; | 341 }; |
339 | 342 |
340 for (const auto& test : tests) { | 343 for (const auto& test : tests) { |
341 [[permissions class] | 344 [[permissions class] |
342 setIsTouchToSearchAvailableOnDevice:test.enabled_on_device]; | 345 setIsTouchToSearchAvailableOnDevice:test.enabled_on_device]; |
343 permissions.get().preferenceState = test.prefState; | 346 permissions.preferenceState = test.prefState; |
344 permissions.get().isVoiceOverEnabled = test.voiceover_enabled; | 347 permissions.isVoiceOverEnabled = test.voiceover_enabled; |
345 permissions.get().areContextualSearchQueriesSupported = | 348 permissions.areContextualSearchQueriesSupported = test.queries_allowed; |
346 test.queries_allowed; | |
347 EXPECT_EQ(test.expect_available, [permissions canEnable]); | 349 EXPECT_EQ(test.expect_available, [permissions canEnable]); |
348 } | 350 } |
349 } | 351 } |
350 | 352 |
351 TEST_F(TouchToSearchPermissionsMediatorTest, AudienceNotifications) { | 353 TEST_F(TouchToSearchPermissionsMediatorTest, AudienceNotifications) { |
352 base::scoped_nsobject<id> audience( | 354 id audience = [[TestTouchToSearchPermissionsAudience alloc] init]; |
353 [[TestTouchToSearchPermissionsAudience alloc] init]); | |
354 [tts_permissions_ setAudience:audience]; | 355 [tts_permissions_ setAudience:audience]; |
355 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(50); | 356 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(50); |
356 [[NSNotificationCenter defaultCenter] | 357 [[NSNotificationCenter defaultCenter] |
357 postNotificationName:UIApplicationWillEnterForegroundNotification | 358 postNotificationName:UIApplicationWillEnterForegroundNotification |
358 object:[UIApplication sharedApplication]]; | 359 object:[UIApplication sharedApplication]]; |
359 // Audience call is asynchronous, so expect nothing yet. | 360 // Audience call is asynchronous, so expect nothing yet. |
360 EXPECT_FALSE([audience updated]); | 361 EXPECT_FALSE([audience updated]); |
361 // Wait for async call. | 362 // Wait for async call. |
362 base::test::ios::WaitUntilCondition( | 363 base::test::ios::WaitUntilCondition( |
363 ^bool(void) { | 364 ^bool(void) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 BrowserState()->GetPrefs()->SetString(prefs::kContextualSearchEnabled, | 424 BrowserState()->GetPrefs()->SetString(prefs::kContextualSearchEnabled, |
424 "true"); | 425 "true"); |
425 // Audience call is asynchronous, so expect nothing yet. | 426 // Audience call is asynchronous, so expect nothing yet. |
426 EXPECT_FALSE([audience updated]); | 427 EXPECT_FALSE([audience updated]); |
427 // Wait long enough for async call not to occur. | 428 // Wait long enough for async call not to occur. |
428 base::test::ios::SpinRunLoopWithMaxDelay(delay); | 429 base::test::ios::SpinRunLoopWithMaxDelay(delay); |
429 EXPECT_FALSE([audience updated]); | 430 EXPECT_FALSE([audience updated]); |
430 // Reset |audience|. | 431 // Reset |audience|. |
431 [audience setUpdated:NO]; | 432 [audience setUpdated:NO]; |
432 | 433 |
433 base::scoped_nsobject<id> audience2( | 434 id audience2 = [[TestTouchToSearchPermissionsAudience alloc] init]; |
434 [[TestTouchToSearchPermissionsAudience alloc] init]); | |
435 // If the permissions object is destroyed, queued notifications should still | 435 // If the permissions object is destroyed, queued notifications should still |
436 // be sent. | 436 // be sent. |
437 [tts_permissions_ setAudience:audience2]; | 437 [tts_permissions_ setAudience:audience2]; |
438 [[NSNotificationCenter defaultCenter] | 438 [[NSNotificationCenter defaultCenter] |
439 postNotificationName:UIAccessibilityVoiceOverStatusChanged | 439 postNotificationName:UIAccessibilityVoiceOverStatusChanged |
440 object:nil]; | 440 object:nil]; |
441 tts_permissions_.reset(); | 441 tts_permissions_ = nil; |
442 base::test::ios::WaitUntilCondition( | 442 base::test::ios::WaitUntilCondition( |
443 ^bool(void) { | 443 ^bool(void) { |
444 return [audience2 updated]; | 444 return [audience2 updated]; |
445 }, | 445 }, |
446 false, delay); | 446 false, delay); |
447 EXPECT_TRUE([audience2 updated]); | 447 EXPECT_TRUE([audience2 updated]); |
448 } | 448 } |
449 | 449 |
450 TEST_F(TouchToSearchPermissionsMediatorTest, AudiencePrefsSynchronous) { | 450 TEST_F(TouchToSearchPermissionsMediatorTest, AudiencePrefsSynchronous) { |
451 id audience = [OCMockObject | 451 id audience = [OCMockObject |
452 niceMockForProtocol:@protocol(TouchToSearchPermissionsChangeAudience)]; | 452 niceMockForProtocol:@protocol(TouchToSearchPermissionsChangeAudience)]; |
453 [tts_permissions_ setAudience:audience]; | 453 [tts_permissions_ setAudience:audience]; |
454 | 454 |
455 // Test that setting preferences through the same permissions object triggers | 455 // Test that setting preferences through the same permissions object triggers |
456 // audience methods. | 456 // audience methods. |
457 [[audience expect] | 457 [[audience expect] |
458 touchToSearchDidChangePreferenceState:TouchToSearch::ENABLED]; | 458 touchToSearchDidChangePreferenceState:TouchToSearch::ENABLED]; |
459 [tts_permissions_ setPreferenceState:TouchToSearch::ENABLED]; | 459 [tts_permissions_ setPreferenceState:TouchToSearch::ENABLED]; |
460 EXPECT_OCMOCK_VERIFY(audience); | 460 EXPECT_OCMOCK_VERIFY(audience); |
461 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; | 461 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; |
462 | 462 |
463 // Test that setting preferences through another permissions object triggers | 463 // Test that setting preferences through another permissions object triggers |
464 // audience methods. | 464 // audience methods. |
465 base::scoped_nsobject<TouchToSearchPermissionsMediator> other_permissions( | 465 TouchToSearchPermissionsMediator* other_permissions = |
466 [[TouchToSearchPermissionsMediator alloc] | 466 [[TouchToSearchPermissionsMediator alloc] |
467 initWithBrowserState:BrowserState()]); | 467 initWithBrowserState:BrowserState()]; |
468 [[audience expect] | 468 [[audience expect] |
469 touchToSearchDidChangePreferenceState:TouchToSearch::ENABLED]; | 469 touchToSearchDidChangePreferenceState:TouchToSearch::ENABLED]; |
470 [other_permissions setPreferenceState:TouchToSearch::ENABLED]; | 470 [other_permissions setPreferenceState:TouchToSearch::ENABLED]; |
471 EXPECT_OCMOCK_VERIFY(audience); | 471 EXPECT_OCMOCK_VERIFY(audience); |
472 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; | 472 [tts_permissions_ setPreferenceState:TouchToSearch::DISABLED]; |
473 | 473 |
474 // Test that setting preferences through the prefs system triggers audience | 474 // Test that setting preferences through the prefs system triggers audience |
475 // methods. | 475 // methods. |
476 [[audience expect] | 476 [[audience expect] |
477 touchToSearchDidChangePreferenceState:TouchToSearch::ENABLED]; | 477 touchToSearchDidChangePreferenceState:TouchToSearch::ENABLED]; |
478 BrowserState()->GetPrefs()->SetString(prefs::kContextualSearchEnabled, | 478 BrowserState()->GetPrefs()->SetString(prefs::kContextualSearchEnabled, |
479 "true"); | 479 "true"); |
480 EXPECT_OCMOCK_VERIFY(audience); | 480 EXPECT_OCMOCK_VERIFY(audience); |
481 } | 481 } |
482 | 482 |
483 TEST_F(TouchToSearchPermissionsMediatorTest, OTR) { | 483 TEST_F(TouchToSearchPermissionsMediatorTest, OTR) { |
484 ios::ChromeBrowserState* otr_state = | 484 ios::ChromeBrowserState* otr_state = |
485 BrowserState()->GetOffTheRecordChromeBrowserState(); | 485 BrowserState()->GetOffTheRecordChromeBrowserState(); |
486 base::scoped_nsobject<TouchToSearchPermissionsMediator> permissions([ | 486 TouchToSearchPermissionsMediator* permissions = |
487 [TouchToSearchPermissionsMediator alloc] initWithBrowserState:otr_state]); | 487 [[TouchToSearchPermissionsMediator alloc] initWithBrowserState:otr_state]; |
488 | 488 |
489 EXPECT_FALSE([permissions canEnable]); | 489 EXPECT_FALSE([permissions canEnable]); |
490 EXPECT_FALSE([permissions canSendPageURLs]); | 490 EXPECT_FALSE([permissions canSendPageURLs]); |
491 EXPECT_FALSE([permissions canEnable]); | 491 EXPECT_FALSE([permissions canEnable]); |
492 EXPECT_FALSE([permissions canPreloadSearchResults]); | 492 EXPECT_FALSE([permissions canPreloadSearchResults]); |
493 EXPECT_EQ(TouchToSearch::DISABLED, [permissions preferenceState]); | 493 EXPECT_EQ(TouchToSearch::DISABLED, [permissions preferenceState]); |
494 | 494 |
495 otr_state->GetPrefs()->SetString(prefs::kContextualSearchEnabled, "true"); | 495 otr_state->GetPrefs()->SetString(prefs::kContextualSearchEnabled, "true"); |
496 EXPECT_EQ(TouchToSearch::DISABLED, [permissions preferenceState]); | 496 EXPECT_EQ(TouchToSearch::DISABLED, [permissions preferenceState]); |
497 EXPECT_FALSE([permissions canEnable]); | 497 EXPECT_FALSE([permissions canEnable]); |
498 | 498 |
499 EXPECT_EQ(nil, [permissions audience]); | 499 EXPECT_EQ(nil, [permissions audience]); |
500 id audience = [OCMockObject | 500 id audience = [OCMockObject |
501 niceMockForProtocol:@protocol(TouchToSearchPermissionsChangeAudience)]; | 501 niceMockForProtocol:@protocol(TouchToSearchPermissionsChangeAudience)]; |
502 [permissions setAudience:audience]; | 502 [permissions setAudience:audience]; |
503 EXPECT_EQ(nil, [permissions audience]); | 503 EXPECT_EQ(nil, [permissions audience]); |
504 } | 504 } |
505 | 505 |
506 TEST_F(TouchToSearchPermissionsMediatorTest, AudienceRemovedNotifications) { | 506 TEST_F(TouchToSearchPermissionsMediatorTest, AudienceRemovedNotifications) { |
507 @autoreleasepool { | 507 @autoreleasepool { |
508 base::scoped_nsobject<id> audience( | 508 id audience = [[TestTouchToSearchPermissionsAudience alloc] init]; |
509 [[TestTouchToSearchPermissionsAudience alloc] init]); | |
510 [tts_permissions_ setAudience:audience]; | 509 [tts_permissions_ setAudience:audience]; |
511 EXPECT_TRUE([tts_permissions_ observing]); | 510 EXPECT_TRUE([tts_permissions_ observing]); |
512 audience.reset(); | 511 audience = nil; |
513 } | 512 } |
514 // Permissions shouldn't be observing after notifying a nil audience. | 513 // Permissions shouldn't be observing after notifying a nil audience. |
515 [[NSNotificationCenter defaultCenter] | 514 [[NSNotificationCenter defaultCenter] |
516 postNotificationName:UIAccessibilityVoiceOverStatusChanged | 515 postNotificationName:UIAccessibilityVoiceOverStatusChanged |
517 object:nil]; | 516 object:nil]; |
518 EXPECT_FALSE([tts_permissions_ observing]); | 517 EXPECT_FALSE([tts_permissions_ observing]); |
519 | 518 |
520 // Permissions shouldn't observe while still observing. | 519 // Permissions shouldn't observe while still observing. |
521 base::scoped_nsobject<id> audience( | 520 id audience = [[TestTouchToSearchPermissionsAudience alloc] init]; |
522 [[TestTouchToSearchPermissionsAudience alloc] init]); | |
523 [tts_permissions_ setAudience:audience]; | 521 [tts_permissions_ setAudience:audience]; |
524 audience.reset(); | 522 audience = nil; |
525 audience.reset([[TestTouchToSearchPermissionsAudience alloc] init]); | 523 audience = [[TestTouchToSearchPermissionsAudience alloc] init]; |
526 [tts_permissions_ setAudience:audience]; | 524 [tts_permissions_ setAudience:audience]; |
527 } | 525 } |
528 | 526 |
529 #pragma mark - Unit tests for availability class method. | 527 #pragma mark - Unit tests for availability class method. |
530 | 528 |
531 TEST(TouchToSearchPermissionsAvailabilityTest, CommandLinePermissions) { | 529 TEST(TouchToSearchPermissionsAvailabilityTest, CommandLinePermissions) { |
532 const struct { | 530 const struct { |
533 bool set_disable; | 531 bool set_disable; |
534 bool set_enable; | 532 bool set_enable; |
535 bool expect_available; | 533 bool expect_available; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 580 } |
583 EXPECT_EQ( | 581 EXPECT_EQ( |
584 [TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice], | 582 [TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice], |
585 test.expect_available); | 583 test.expect_available); |
586 } | 584 } |
587 } | 585 } |
588 | 586 |
589 #pragma mark - Unit tests for mock class | 587 #pragma mark - Unit tests for mock class |
590 | 588 |
591 TEST(MockTouchToSearchPermissionsTest, Mocking) { | 589 TEST(MockTouchToSearchPermissionsTest, Mocking) { |
592 base::scoped_nsobject<MockTouchToSearchPermissionsMediator> | 590 MockTouchToSearchPermissionsMediator* scoped_permissions = |
593 scoped_permissions([[MockTouchToSearchPermissionsMediator alloc] | 591 [[MockTouchToSearchPermissionsMediator alloc] |
594 initWithBrowserState:nullptr]); | 592 initWithBrowserState:nullptr]; |
595 MockTouchToSearchPermissionsMediator* permissions = scoped_permissions; | 593 MockTouchToSearchPermissionsMediator* permissions = scoped_permissions; |
596 | 594 |
597 const GURL test_urls[] = { | 595 const GURL test_urls[] = { |
598 GURL("https://www.some-website.com/"), | 596 GURL("https://www.some-website.com/"), |
599 GURL("http://www.some-website.com/"), GURL(""), | 597 GURL("http://www.some-website.com/"), GURL(""), |
600 }; | 598 }; |
601 | 599 |
602 // Default expectations from mocked methods. | 600 // Default expectations from mocked methods. |
603 EXPECT_TRUE([[permissions class] isTouchToSearchAvailableOnDevice]); | 601 EXPECT_TRUE([[permissions class] isTouchToSearchAvailableOnDevice]); |
604 EXPECT_TRUE([permissions canSendPageURLs]); | 602 EXPECT_TRUE([permissions canSendPageURLs]); |
(...skipping 25 matching lines...) Expand all Loading... |
630 TouchToSearch::DISABLED, TouchToSearch::UNDECIDED, TouchToSearch::ENABLED, | 628 TouchToSearch::DISABLED, TouchToSearch::UNDECIDED, TouchToSearch::ENABLED, |
631 }; | 629 }; |
632 | 630 |
633 for (const auto& state : states) { | 631 for (const auto& state : states) { |
634 permissions.preferenceState = state; | 632 permissions.preferenceState = state; |
635 EXPECT_EQ(state, permissions.preferenceState); | 633 EXPECT_EQ(state, permissions.preferenceState); |
636 } | 634 } |
637 } | 635 } |
638 | 636 |
639 } // namespace | 637 } // namespace |
OLD | NEW |