Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/callback.h" | |
| 7 #include "base/run_loop.h" | |
| 8 #include "chrome/browser/webshare/share_service_impl.h" | |
| 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 10 #include "mojo/public/cpp/bindings/interface_request.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 class ShareServiceTest : public ChromeRenderViewHostTestHarness { | |
|
Sam McNally
2016/12/09 04:23:45
Does this need to be a ChromeRenderViewHostTestHar
constantina
2016/12/12 02:50:32
I believe it is needed to make |run_loop| work cor
Matt Giuca
2016/12/12 04:33:04
dominickn@ said this was necessary to make it actu
| |
| 15 public: | |
| 16 ShareServiceTest() {} | |
|
Sam McNally
2016/12/09 04:23:45
= default;
constantina
2016/12/12 02:50:33
Done.
| |
| 17 ~ShareServiceTest() override {} | |
|
Sam McNally
2016/12/09 04:23:45
= default;
constantina
2016/12/12 02:50:32
Done.
| |
| 18 | |
| 19 void SetUp() override { | |
| 20 ChromeRenderViewHostTestHarness::SetUp(); | |
| 21 | |
| 22 ShareServiceImpl::Create(mojo::GetProxy(&share_service_)); | |
| 23 } | |
| 24 | |
| 25 void callback(const base::Optional<std::string>& expected, | |
|
Sam McNally
2016/12/09 04:23:45
DidShare()
constantina
2016/12/12 02:50:32
Done.
| |
| 26 const base::Optional<std::string>& str) { | |
| 27 EXPECT_EQ(expected, str); | |
| 28 | |
| 29 if (!on_callback_.is_null()) | |
| 30 on_callback_.Run(); | |
| 31 } | |
| 32 | |
| 33 blink::mojom::ShareServicePtr share_service_; | |
| 34 base::Closure on_callback_; | |
| 35 }; | |
| 36 | |
| 37 // Basic test to check the Share method uses the callback as expected. | |
| 38 TEST_F(ShareServiceTest, ShareCallbackSuccess) { | |
|
Sam McNally
2016/12/09 04:23:45
It's not exactly a successful share.
constantina
2016/12/12 02:50:32
Changed. This test will probably be changed/remove
| |
| 39 const GURL url("https://www.google.com"); | |
| 40 | |
| 41 base::RunLoop run_loop; | |
| 42 on_callback_ = run_loop.QuitClosure(); | |
| 43 | |
| 44 base::Callback<void(const base::Optional<std::string>&)> callback = | |
| 45 base::Bind( | |
| 46 &ShareServiceTest::callback, base::Unretained(this), | |
| 47 base::Optional<std::string>("Not implemented: navigator.share")); | |
| 48 share_service_->Share("title", "text", url, callback); | |
| 49 | |
| 50 run_loop.Run(); | |
| 51 } | |
| OLD | NEW |