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" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 } | 26 } |
| 27 // Required for CRWJSWindowIdManager creation. | 27 // Required for CRWJSWindowIdManager creation. |
| 28 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; | 28 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; |
| 29 // Testable CRWJSWindowIdManager. | 29 // Testable CRWJSWindowIdManager. |
| 30 base::scoped_nsobject<CRWJSWindowIdManager> manager_; | 30 base::scoped_nsobject<CRWJSWindowIdManager> manager_; |
| 31 // WebClient required for getting early page script, which must be injected | 31 // WebClient required for getting early page script, which must be injected |
| 32 // before CRWJSWindowIdManager. | 32 // before CRWJSWindowIdManager. |
| 33 web::WebClient web_client_; | 33 web::WebClient web_client_; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // TODO(jyquinn): enable this test (crbug.com/465898). | 36 // Tests that reinjection of window ID JS results in a different window ID. |
| 37 TEST_F(JSWindowIDManagerTest, DISABLED_WindowID) { | 37 // TODO(ios): This test only works for the current implementation using |
| 38 // UIWebView. CRWTestJSInjectionReceiver should be re-written to eliminate | |
| 39 // web view specificity (crbug.com/486840). | |
| 40 TEST_F(JSWindowIDManagerTest, WindowIDReinjection) { | |
| 38 EXPECT_TRUE(manager_.get()); | 41 EXPECT_TRUE(manager_.get()); |
| 39 [manager_ inject]; | 42 [manager_ inject]; |
| 40 NSString* windowID = [manager_ windowId]; | 43 NSString* windowID = [manager_ windowId]; |
| 41 EXPECT_EQ(32U, [windowID length]); | 44 EXPECT_EQ(32U, [windowID length]); |
| 42 // Inject a second time to check that the ID is different. | 45 // Reset the __gCrWeb object to enable reinjection. |
| 43 [manager_ inject]; | 46 [receiver_ evaluateJavaScript:@"__gCrWeb = undefined;" |
|
Eugene But (OOO till 7-30)
2015/05/12 17:14:32
Please don't use async API in tests. If evaluation
Jackie Quinn
2015/05/12 17:50:01
Done.
| |
| 44 NSString* windowID2 = [manager_ windowId]; | 47 stringResultHandler:^(NSString* result, NSError* error) { |
| 45 EXPECT_FALSE([windowID isEqualToString:windowID2]); | 48 // Inject a second time to check that the ID is different. |
| 49 [manager_ inject]; | |
| 50 NSString* windowID2 = [manager_ windowId]; | |
| 51 EXPECT_FALSE([windowID isEqualToString:windowID2]); | |
| 52 }]; | |
| 46 } | 53 } |
| 47 | 54 |
| 48 TEST_F(JSWindowIDManagerTest, WindowIDDifferent) { | 55 // Tests that window ID injection by a second manager results in a different |
| 56 // window ID. | |
| 57 TEST_F(JSWindowIDManagerTest, WindowIDDifferentManager) { | |
| 49 [manager_ inject]; | 58 [manager_ inject]; |
| 50 NSString* windowID = [manager_ windowId]; | 59 NSString* windowID = [manager_ windowId]; |
| 51 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver2( | 60 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver2( |
| 52 [[CRWTestJSInjectionReceiver alloc] init]); | 61 [[CRWTestJSInjectionReceiver alloc] init]); |
| 53 base::scoped_nsobject<CRWJSWindowIdManager> manager2( | 62 base::scoped_nsobject<CRWJSWindowIdManager> manager2( |
| 54 [[CRWJSWindowIdManager alloc] initWithReceiver:receiver2]); | 63 [[CRWJSWindowIdManager alloc] initWithReceiver:receiver2]); |
| 55 [manager2 inject]; | 64 [manager2 inject]; |
| 56 NSString* windowID2 = [manager2 windowId]; | 65 NSString* windowID2 = [manager2 windowId]; |
| 57 EXPECT_NSNE(windowID, windowID2); | 66 EXPECT_NSNE(windowID, windowID2); |
| 58 } | 67 } |
| 59 | 68 |
| 60 } // namespace | 69 } // namespace |
| OLD | NEW |