Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: ios/web/web_state/js/crw_js_window_id_manager_unittest.mm

Issue 1129763003: Re-enable JSWindowIDManagerTest.WindowID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use web::EvaluateJavaScriptAsString Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/public/web_state/js/crw_js_window_id_manager_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "ios/web/public/test/js_test_util.h"
9 #include "ios/web/public/web_client.h" 10 #include "ios/web/public/web_client.h"
10 #import "testing/gtest_mac.h" 11 #import "testing/gtest_mac.h"
11 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
12 13
13 namespace { 14 namespace {
14 15
15 class JSWindowIDManagerTest : public PlatformTest { 16 class JSWindowIDManagerTest : public PlatformTest {
16 protected: 17 protected:
17 void SetUp() override { 18 void SetUp() override {
18 PlatformTest::SetUp(); 19 PlatformTest::SetUp();
19 receiver_.reset([[CRWTestJSInjectionReceiver alloc] init]); 20 receiver_.reset([[CRWTestJSInjectionReceiver alloc] init]);
20 manager_.reset([[CRWJSWindowIdManager alloc] initWithReceiver:receiver_]); 21 manager_.reset([[CRWJSWindowIdManager alloc] initWithReceiver:receiver_]);
21 web::SetWebClient(&web_client_); 22 web::SetWebClient(&web_client_);
22 } 23 }
23 void TearDown() override { 24 void TearDown() override {
24 web::SetWebClient(nullptr); 25 web::SetWebClient(nullptr);
25 PlatformTest::TearDown(); 26 PlatformTest::TearDown();
26 } 27 }
27 // Required for CRWJSWindowIdManager creation. 28 // Required for CRWJSWindowIdManager creation.
28 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; 29 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_;
29 // Testable CRWJSWindowIdManager. 30 // Testable CRWJSWindowIdManager.
30 base::scoped_nsobject<CRWJSWindowIdManager> manager_; 31 base::scoped_nsobject<CRWJSWindowIdManager> manager_;
31 // WebClient required for getting early page script, which must be injected 32 // WebClient required for getting early page script, which must be injected
32 // before CRWJSWindowIdManager. 33 // before CRWJSWindowIdManager.
33 web::WebClient web_client_; 34 web::WebClient web_client_;
34 }; 35 };
35 36
36 // TODO(jyquinn): enable this test (crbug.com/465898). 37 // Tests that reinjection of window ID JS results in a different window ID.
37 TEST_F(JSWindowIDManagerTest, DISABLED_WindowID) { 38 // TODO(ios): This test only works for the current implementation using
39 // UIWebView. CRWTestJSInjectionReceiver should be re-written to eliminate
40 // web view specificity (crbug.com/486840).
41 TEST_F(JSWindowIDManagerTest, WindowIDReinjection) {
38 EXPECT_TRUE(manager_.get()); 42 EXPECT_TRUE(manager_.get());
39 [manager_ inject]; 43 [manager_ inject];
40 NSString* windowID = [manager_ windowId]; 44 NSString* windowID = [manager_ windowId];
41 EXPECT_EQ(32U, [windowID length]); 45 EXPECT_EQ(32U, [windowID length]);
46 // Reset the __gCrWeb object to enable reinjection.
47 web::EvaluateJavaScriptAsString(manager_, @"__gCrWeb = undefined;");
42 // Inject a second time to check that the ID is different. 48 // Inject a second time to check that the ID is different.
43 [manager_ inject]; 49 [manager_ inject];
44 NSString* windowID2 = [manager_ windowId]; 50 NSString* windowID2 = [manager_ windowId];
45 EXPECT_FALSE([windowID isEqualToString:windowID2]); 51 EXPECT_FALSE([windowID isEqualToString:windowID2]);
46 } 52 }
47 53
48 TEST_F(JSWindowIDManagerTest, WindowIDDifferent) { 54 // Tests that window ID injection by a second manager results in a different
55 // window ID.
56 TEST_F(JSWindowIDManagerTest, WindowIDDifferentManager) {
49 [manager_ inject]; 57 [manager_ inject];
50 NSString* windowID = [manager_ windowId]; 58 NSString* windowID = [manager_ windowId];
51 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver2( 59 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver2(
52 [[CRWTestJSInjectionReceiver alloc] init]); 60 [[CRWTestJSInjectionReceiver alloc] init]);
53 base::scoped_nsobject<CRWJSWindowIdManager> manager2( 61 base::scoped_nsobject<CRWJSWindowIdManager> manager2(
54 [[CRWJSWindowIdManager alloc] initWithReceiver:receiver2]); 62 [[CRWJSWindowIdManager alloc] initWithReceiver:receiver2]);
55 [manager2 inject]; 63 [manager2 inject];
56 NSString* windowID2 = [manager2 windowId]; 64 NSString* windowID2 = [manager2 windowId];
57 EXPECT_NSNE(windowID, windowID2); 65 EXPECT_NSNE(windowID, windowID2);
58 } 66 }
59 67
60 } // namespace 68 } // namespace
OLDNEW
« no previous file with comments | « ios/web/public/web_state/js/crw_js_window_id_manager_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698