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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_observer_unittest.mm

Issue 2351893003: Remove __gCrWeb.invokeOnHostImmediate. (Closed)
Patch Set: Remove early return. Created 4 years, 2 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/web_state/ui/crw_web_controller.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/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #import "ios/testing/ocmock_complex_type_helper.h" 10 #import "ios/testing/ocmock_complex_type_helper.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 std::string message; 52 std::string message;
53 base::JSONWriter::Write(command, &message); 53 base::JSONWriter::Write(command, &message);
54 ExecuteJavaScript([NSString 54 ExecuteJavaScript([NSString
55 stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)", message.c_str()]); 55 stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)", message.c_str()]);
56 WaitForBackgroundTasks(); 56 WaitForBackgroundTasks();
57 ASSERT_EQ(1U, [fake_web_controller_observer_ commandsReceived].size()); 57 ASSERT_EQ(1U, [fake_web_controller_observer_ commandsReceived].size());
58 EXPECT_TRUE( 58 EXPECT_TRUE(
59 [fake_web_controller_observer_ commandsReceived][0]->Equals(&command)); 59 [fake_web_controller_observer_ commandsReceived][0]->Equals(&command));
60 } 60 }
61 61
62 // Tests that web controller receives an immediate JS message from the page.
63 TEST_F(CRWWebControllerObserverTest, HandleImmediateCommand) {
64 LoadHtml(@"<p></p>");
65 ASSERT_NSNE(@"http://testimmediate#target",
66 [web_controller() externalRequestWindowName]);
67 // The only valid immediate commands are window.unload and externalRequest.
68 base::DictionaryValue command;
69 command.SetString("command", "externalRequest");
70 command.SetString("href", "http://testimmediate");
71 command.SetString("target", "target");
72 command.SetString("referrerPolicy", "referrerPolicy");
73 std::string message;
74 base::JSONWriter::Write(command, &message);
75 ExecuteJavaScript(
76 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHostImmediate(%s)",
77 message.c_str()]);
78 WaitForBackgroundTasks();
79 ASSERT_NSEQ(@"http://testimmediate#target",
80 [web_controller() externalRequestWindowName]);
81 }
82
83 // Send a large number of commands and check each one is immediately received. 62 // Send a large number of commands and check each one is immediately received.
84 TEST_F(CRWWebControllerObserverTest, HandleMultipleCommands) { 63 TEST_F(CRWWebControllerObserverTest, HandleMultipleCommands) {
85 LoadHtml(@"<p></p>"); 64 LoadHtml(@"<p></p>");
86 65
87 base::DictionaryValue command; 66 base::DictionaryValue command;
88 command.SetString("command", "test.testMessage"); 67 command.SetString("command", "test.testMessage");
89 int kNumberMessages = 200; 68 int kNumberMessages = 200;
90 for (int count = 0; count <= kNumberMessages; count++) { 69 for (int count = 0; count <= kNumberMessages; count++) {
91 std::string message; 70 std::string message;
92 command.SetInteger("number", count); 71 command.SetInteger("number", count);
93 base::JSONWriter::Write(command, &message); 72 base::JSONWriter::Write(command, &message);
94 ASSERT_EQ(0U, [fake_web_controller_observer_ commandsReceived].size()); 73 ASSERT_EQ(0U, [fake_web_controller_observer_ commandsReceived].size());
95 ExecuteJavaScript( 74 ExecuteJavaScript(
96 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)", 75 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)",
97 message.c_str()]); 76 message.c_str()]);
98 WaitForBackgroundTasks(); 77 WaitForBackgroundTasks();
99 ASSERT_EQ(1U, [fake_web_controller_observer_ commandsReceived].size()); 78 ASSERT_EQ(1U, [fake_web_controller_observer_ commandsReceived].size());
100 EXPECT_TRUE( 79 EXPECT_TRUE(
101 [fake_web_controller_observer_ commandsReceived][0]->Equals(&command)); 80 [fake_web_controller_observer_ commandsReceived][0]->Equals(&command));
102 [fake_web_controller_observer_ commandsReceived].clear(); 81 [fake_web_controller_observer_ commandsReceived].clear();
103 ASSERT_EQ(0U, [fake_web_controller_observer_ commandsReceived].size()); 82 ASSERT_EQ(0U, [fake_web_controller_observer_ commandsReceived].size());
104 } 83 }
105 } 84 }
106 85
107 } // namespace web 86 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698