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 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 5 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #import "ios/web/public/test/crw_test_js_injection_receiver.h" | 8 #import "ios/web/public/test/crw_test_js_injection_receiver.h" |
| 9 #include "ios/web/public/web_client.h" | 9 #include "ios/web/public/web_client.h" |
| 10 #import "testing/gtest_mac.h" | 10 #import "testing/gtest_mac.h" |
| 11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 12 | 12 |
| 13 // Test Window ID Manager with the ability to bypass hasBeenInjected check in | |
| 14 // the inject method. | |
| 15 @interface CRWTestJSWindowIdManager : CRWJSWindowIdManager | |
| 16 // Inject script, bypassing hasBeenInjected check. | |
| 17 - (void)forceInject; | |
| 18 @end | |
| 19 | |
| 20 @implementation CRWTestJSWindowIdManager | |
| 21 - (void)forceInject { | |
|
Eugene But (OOO till 7-30)
2015/05/09 16:40:37
The fact that second injection does not happen is
Jackie Quinn
2015/05/11 18:21:33
Just changing the beacon won't do anything for WKW
Jackie Quinn
2015/05/12 17:04:38
As discussed offline, changing the presence beacon
| |
| 22 [[self receiver] injectScript:[self injectionContent] forClass:[self class]]; | |
| 23 } | |
| 24 @end | |
| 25 | |
| 13 namespace { | 26 namespace { |
| 14 | 27 |
| 15 class JSWindowIDManagerTest : public PlatformTest { | 28 class JSWindowIDManagerTest : public PlatformTest { |
| 16 protected: | 29 protected: |
| 17 void SetUp() override { | 30 void SetUp() override { |
| 18 PlatformTest::SetUp(); | 31 PlatformTest::SetUp(); |
| 19 receiver_.reset([[CRWTestJSInjectionReceiver alloc] init]); | 32 receiver_.reset([[CRWTestJSInjectionReceiver alloc] init]); |
| 20 manager_.reset([[CRWJSWindowIdManager alloc] initWithReceiver:receiver_]); | 33 manager_.reset( |
| 34 [[CRWTestJSWindowIdManager alloc] initWithReceiver:receiver_]); | |
| 21 web::SetWebClient(&web_client_); | 35 web::SetWebClient(&web_client_); |
| 22 } | 36 } |
| 23 void TearDown() override { | 37 void TearDown() override { |
| 24 web::SetWebClient(nullptr); | 38 web::SetWebClient(nullptr); |
| 25 PlatformTest::TearDown(); | 39 PlatformTest::TearDown(); |
| 26 } | 40 } |
| 27 // Required for CRWJSWindowIdManager creation. | 41 // Required for CRWJSWindowIdManager creation. |
| 28 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; | 42 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; |
| 29 // Testable CRWJSWindowIdManager. | 43 // Testable CRWJSWindowIdManager. |
| 30 base::scoped_nsobject<CRWJSWindowIdManager> manager_; | 44 base::scoped_nsobject<CRWTestJSWindowIdManager> manager_; |
| 31 // WebClient required for getting early page script, which must be injected | 45 // WebClient required for getting early page script, which must be injected |
| 32 // before CRWJSWindowIdManager. | 46 // before CRWJSWindowIdManager. |
| 33 web::WebClient web_client_; | 47 web::WebClient web_client_; |
| 34 }; | 48 }; |
| 35 | 49 |
| 36 // TODO(jyquinn): enable this test (crbug.com/465898). | 50 TEST_F(JSWindowIDManagerTest, WindowID) { |
|
Eugene But (OOO till 7-30)
2015/05/09 16:40:37
NIT: Let's take a chance to add a comment for this
Jackie Quinn
2015/05/12 17:04:37
Done.
| |
| 37 TEST_F(JSWindowIDManagerTest, DISABLED_WindowID) { | |
| 38 EXPECT_TRUE(manager_.get()); | 51 EXPECT_TRUE(manager_.get()); |
| 39 [manager_ inject]; | 52 [manager_ inject]; |
| 40 NSString* windowID = [manager_ windowId]; | 53 NSString* windowID = [manager_ windowId]; |
| 41 EXPECT_EQ(32U, [windowID length]); | 54 EXPECT_EQ(32U, [windowID length]); |
| 42 // Inject a second time to check that the ID is different. | 55 // Inject a second time to check that the ID is different. |
| 43 [manager_ inject]; | 56 [manager_ forceInject]; |
| 44 NSString* windowID2 = [manager_ windowId]; | 57 NSString* windowID2 = [manager_ windowId]; |
| 45 EXPECT_FALSE([windowID isEqualToString:windowID2]); | 58 EXPECT_FALSE([windowID isEqualToString:windowID2]); |
| 46 } | 59 } |
| 47 | 60 |
| 48 TEST_F(JSWindowIDManagerTest, WindowIDDifferent) { | 61 TEST_F(JSWindowIDManagerTest, WindowIDDifferent) { |
| 49 [manager_ inject]; | 62 [manager_ inject]; |
| 50 NSString* windowID = [manager_ windowId]; | 63 NSString* windowID = [manager_ windowId]; |
| 51 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver2( | 64 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver2( |
| 52 [[CRWTestJSInjectionReceiver alloc] init]); | 65 [[CRWTestJSInjectionReceiver alloc] init]); |
| 53 base::scoped_nsobject<CRWJSWindowIdManager> manager2( | 66 base::scoped_nsobject<CRWJSWindowIdManager> manager2( |
| 54 [[CRWJSWindowIdManager alloc] initWithReceiver:receiver2]); | 67 [[CRWJSWindowIdManager alloc] initWithReceiver:receiver2]); |
| 55 [manager2 inject]; | 68 [manager2 inject]; |
| 56 NSString* windowID2 = [manager2 windowId]; | 69 NSString* windowID2 = [manager2 windowId]; |
| 57 EXPECT_NSNE(windowID, windowID2); | 70 EXPECT_NSNE(windowID, windowID2); |
| 58 } | 71 } |
| 59 | 72 |
| 60 } // namespace | 73 } // namespace |
| OLD | NEW |