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

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

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase 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 | « gpu/tools/compositor_model_bench/render_tree.cc ('k') | ios/web/webui/web_ui_ios_impl.mm » ('j') | 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 <vector> 7 #include <vector>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 // Tests that web controller receives a JS message from the page. 62 // Tests that web controller receives a JS message from the page.
63 WEB_TEST_F(CRWUIWebViewWebControllerObserverTest, 63 WEB_TEST_F(CRWUIWebViewWebControllerObserverTest,
64 CRWWKWebViewWebControllerObserverTest, 64 CRWWKWebViewWebControllerObserverTest,
65 HandleCommand) { 65 HandleCommand) {
66 this->LoadHtml(@"<p></p>"); 66 this->LoadHtml(@"<p></p>");
67 ASSERT_EQ(0U, [this->fake_web_controller_observer_ commandsReceived].size()); 67 ASSERT_EQ(0U, [this->fake_web_controller_observer_ commandsReceived].size());
68 base::DictionaryValue command; 68 base::DictionaryValue command;
69 command.SetString("command", "test.testMessage"); 69 command.SetString("command", "test.testMessage");
70 std::string message; 70 std::string message;
71 base::JSONWriter::Write(&command, &message); 71 base::JSONWriter::Write(command, &message);
72 this->RunJavaScript([NSString 72 this->RunJavaScript([NSString
73 stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)", message.c_str()]); 73 stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)", message.c_str()]);
74 this->WaitForBackgroundTasks(); 74 this->WaitForBackgroundTasks();
75 ASSERT_EQ(1U, [this->fake_web_controller_observer_ commandsReceived].size()); 75 ASSERT_EQ(1U, [this->fake_web_controller_observer_ commandsReceived].size());
76 EXPECT_TRUE([this->fake_web_controller_observer_ commandsReceived][0]->Equals( 76 EXPECT_TRUE([this->fake_web_controller_observer_ commandsReceived][0]->Equals(
77 &command)); 77 &command));
78 } 78 }
79 79
80 // Tests that web controller receives an immediate JS message from the page. 80 // Tests that web controller receives an immediate JS message from the page.
81 WEB_TEST_F(CRWUIWebViewWebControllerObserverTest, 81 WEB_TEST_F(CRWUIWebViewWebControllerObserverTest,
82 CRWWKWebViewWebControllerObserverTest, 82 CRWWKWebViewWebControllerObserverTest,
83 HandleImmediateCommand) { 83 HandleImmediateCommand) {
84 this->LoadHtml(@"<p></p>"); 84 this->LoadHtml(@"<p></p>");
85 ASSERT_NSNE(@"http://testimmediate#target", 85 ASSERT_NSNE(@"http://testimmediate#target",
86 [this->webController_ externalRequestWindowName]); 86 [this->webController_ externalRequestWindowName]);
87 // The only valid immediate commands are window.unload and externalRequest. 87 // The only valid immediate commands are window.unload and externalRequest.
88 base::DictionaryValue command; 88 base::DictionaryValue command;
89 command.SetString("command", "externalRequest"); 89 command.SetString("command", "externalRequest");
90 command.SetString("href", "http://testimmediate"); 90 command.SetString("href", "http://testimmediate");
91 command.SetString("target", "target"); 91 command.SetString("target", "target");
92 command.SetString("referrerPolicy", "referrerPolicy"); 92 command.SetString("referrerPolicy", "referrerPolicy");
93 std::string message; 93 std::string message;
94 base::JSONWriter::Write(&command, &message); 94 base::JSONWriter::Write(command, &message);
95 this->RunJavaScript( 95 this->RunJavaScript(
96 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHostImmediate(%s)", 96 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHostImmediate(%s)",
97 message.c_str()]); 97 message.c_str()]);
98 this->WaitForBackgroundTasks(); 98 this->WaitForBackgroundTasks();
99 ASSERT_NSEQ(@"http://testimmediate#target", 99 ASSERT_NSEQ(@"http://testimmediate#target",
100 [this->webController_ externalRequestWindowName]); 100 [this->webController_ externalRequestWindowName]);
101 } 101 }
102 102
103 // Send a large number of commands and check each one is immediately received. 103 // Send a large number of commands and check each one is immediately received.
104 WEB_TEST_F(CRWUIWebViewWebControllerObserverTest, 104 WEB_TEST_F(CRWUIWebViewWebControllerObserverTest,
105 CRWWKWebViewWebControllerObserverTest, 105 CRWWKWebViewWebControllerObserverTest,
106 HandleMultipleCommands) { 106 HandleMultipleCommands) {
107 this->LoadHtml(@"<p></p>"); 107 this->LoadHtml(@"<p></p>");
108 108
109 base::DictionaryValue command; 109 base::DictionaryValue command;
110 command.SetString("command", "test.testMessage"); 110 command.SetString("command", "test.testMessage");
111 int kNumberMessages = 200; 111 int kNumberMessages = 200;
112 for (int count = 0; count <= kNumberMessages; count++) { 112 for (int count = 0; count <= kNumberMessages; count++) {
113 std::string message; 113 std::string message;
114 command.SetInteger("number", count); 114 command.SetInteger("number", count);
115 base::JSONWriter::Write(&command, &message); 115 base::JSONWriter::Write(command, &message);
116 ASSERT_EQ(0U, 116 ASSERT_EQ(0U,
117 [this->fake_web_controller_observer_ commandsReceived].size()); 117 [this->fake_web_controller_observer_ commandsReceived].size());
118 this->RunJavaScript( 118 this->RunJavaScript(
119 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)", 119 [NSString stringWithFormat:@"__gCrWeb.message.invokeOnHost(%s)",
120 message.c_str()]); 120 message.c_str()]);
121 this->WaitForBackgroundTasks(); 121 this->WaitForBackgroundTasks();
122 ASSERT_EQ(1U, 122 ASSERT_EQ(1U,
123 [this->fake_web_controller_observer_ commandsReceived].size()); 123 [this->fake_web_controller_observer_ commandsReceived].size());
124 EXPECT_TRUE( 124 EXPECT_TRUE(
125 [this->fake_web_controller_observer_ commandsReceived][0]->Equals( 125 [this->fake_web_controller_observer_ commandsReceived][0]->Equals(
126 &command)); 126 &command));
127 [this->fake_web_controller_observer_ commandsReceived].clear(); 127 [this->fake_web_controller_observer_ commandsReceived].clear();
128 ASSERT_EQ(0U, 128 ASSERT_EQ(0U,
129 [this->fake_web_controller_observer_ commandsReceived].size()); 129 [this->fake_web_controller_observer_ commandsReceived].size());
130 } 130 }
131 } 131 }
132 132
133 } // namespace 133 } // namespace
OLDNEW
« no previous file with comments | « gpu/tools/compositor_model_bench/render_tree.cc ('k') | ios/web/webui/web_ui_ios_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698