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 { |
| 15 public: |
| 16 ShareServiceTest() = default; |
| 17 ~ShareServiceTest() override = default; |
| 18 |
| 19 void SetUp() override { |
| 20 ChromeRenderViewHostTestHarness::SetUp(); |
| 21 |
| 22 ShareServiceImpl::Create(mojo::GetProxy(&share_service_)); |
| 23 } |
| 24 |
| 25 void TearDown() override { |
| 26 ChromeRenderViewHostTestHarness::TearDown(); |
| 27 } |
| 28 |
| 29 void DidShare(const base::Optional<std::string>& expected, |
| 30 const base::Optional<std::string>& str) { |
| 31 EXPECT_EQ(expected, str); |
| 32 |
| 33 if (!on_callback_.is_null()) |
| 34 on_callback_.Run(); |
| 35 } |
| 36 |
| 37 blink::mojom::ShareServicePtr share_service_; |
| 38 base::Closure on_callback_; |
| 39 }; |
| 40 |
| 41 // Basic test to check the Share method calls the callback with the expected |
| 42 // parameters. |
| 43 TEST_F(ShareServiceTest, ShareCallbackParams) { |
| 44 const GURL url("https://www.google.com"); |
| 45 |
| 46 base::RunLoop run_loop; |
| 47 on_callback_ = run_loop.QuitClosure(); |
| 48 |
| 49 base::Callback<void(const base::Optional<std::string>&)> callback = |
| 50 base::Bind( |
| 51 &ShareServiceTest::DidShare, base::Unretained(this), |
| 52 base::Optional<std::string>("Not implemented: navigator.share")); |
| 53 share_service_->Share("title", "text", url, callback); |
| 54 |
| 55 run_loop.Run(); |
| 56 } |
OLD | NEW |