| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 #else | 150 #else |
| 151 #define MAYBE_QueryHandling QueryHandling | 151 #define MAYBE_QueryHandling QueryHandling |
| 152 #endif // ADDRESS_SANITIZER | 152 #endif // ADDRESS_SANITIZER |
| 153 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { | 153 TEST_F(ShellHTTPAppTest, MAYBE_QueryHandling) { |
| 154 PingablePtr pingable1; | 154 PingablePtr pingable1; |
| 155 PingablePtr pingable2; | 155 PingablePtr pingable2; |
| 156 application_impl()->ConnectToService(GetURL("app?foo"), &pingable1); | 156 application_impl()->ConnectToService(GetURL("app?foo"), &pingable1); |
| 157 application_impl()->ConnectToService(GetURL("app?bar"), &pingable2); | 157 application_impl()->ConnectToService(GetURL("app?bar"), &pingable2); |
| 158 | 158 |
| 159 int num_responses = 0; | 159 int num_responses = 0; |
| 160 auto callback = [this, &num_responses](const String& app_url, | 160 auto callbacks_builder = [this, &num_responses](int query_index) { |
| 161 const String& connection_url, | 161 return [this, &num_responses, query_index](const String& app_url, |
| 162 const String& message) { | 162 const String& connection_url, |
| 163 EXPECT_EQ(GetURL("app"), app_url); | 163 const String& message) { |
| 164 EXPECT_EQ("hello", message); | 164 EXPECT_EQ(GetURL("app"), app_url); |
| 165 ++num_responses; | 165 EXPECT_EQ("hello", message); |
| 166 if (num_responses == 1) { | 166 if (query_index == 1) { |
| 167 EXPECT_EQ(GetURL("app?foo"), connection_url); | 167 EXPECT_EQ(GetURL("app?foo"), connection_url); |
| 168 } else if (num_responses == 2) { | 168 } else if (query_index == 2) { |
| 169 EXPECT_EQ(GetURL("app?bar"), connection_url); | 169 EXPECT_EQ(GetURL("app?bar"), connection_url); |
| 170 base::MessageLoop::current()->Quit(); | 170 } else { |
| 171 } else { | 171 CHECK(false); |
| 172 CHECK(false); | 172 } |
| 173 } | 173 ++num_responses; |
| 174 if (num_responses == 2) |
| 175 base::MessageLoop::current()->Quit(); |
| 176 }; |
| 174 }; | 177 }; |
| 175 pingable1->Ping("hello", callback); | 178 pingable1->Ping("hello", callbacks_builder(1)); |
| 176 pingable2->Ping("hello", callback); | 179 pingable2->Ping("hello", callbacks_builder(2)); |
| 177 base::RunLoop().Run(); | 180 base::RunLoop().Run(); |
| 178 } | 181 } |
| 179 | 182 |
| 180 // mojo: URLs can have querystrings too | 183 // mojo: URLs can have querystrings too |
| 181 TEST_F(ShellAppTest, MojoURLQueryHandling) { | 184 TEST_F(ShellAppTest, MojoURLQueryHandling) { |
| 182 PingablePtr pingable; | 185 PingablePtr pingable; |
| 183 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); | 186 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); |
| 184 auto callback = [this](const String& app_url, const String& connection_url, | 187 auto callback = [this](const String& app_url, const String& connection_url, |
| 185 const String& message) { | 188 const String& message) { |
| 186 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); | 189 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); |
| 187 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); | 190 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); |
| 188 EXPECT_EQ("hello", message); | 191 EXPECT_EQ("hello", message); |
| 189 base::MessageLoop::current()->Quit(); | 192 base::MessageLoop::current()->Quit(); |
| 190 }; | 193 }; |
| 191 pingable->Ping("hello", callback); | 194 pingable->Ping("hello", callback); |
| 192 base::RunLoop().Run(); | 195 base::RunLoop().Run(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 } // namespace | 198 } // namespace |
| OLD | NEW |