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 { | |
| 15 public: | |
| 16 ShareServiceTest() {} | |
| 17 ~ShareServiceTest() override {} | |
| 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, | |
| 26 const base::Optional<std::string>& str) { | |
| 27 EXPECT_EQ(expected, str); | |
| 28 | |
| 29 if (!quit_closure_.is_null()) | |
|
Matt Giuca
2016/12/09 02:32:21
Maybe rename this to |on_callback_|, because this
constantina
2016/12/09 02:43:01
I like it. Done.
| |
| 30 quit_closure_.Run(); | |
| 31 } | |
| 32 | |
| 33 blink::mojom::ShareServicePtr share_service_; | |
| 34 base::Closure quit_closure_; | |
| 35 }; | |
| 36 | |
| 37 // Basic test to check the Share method uses the callback as expected. | |
| 38 TEST_F(ShareServiceTest, ShareCallbackSuccess) { | |
| 39 const GURL url("https://www.google.com"); | |
| 40 | |
| 41 base::RunLoop run_loop; | |
| 42 quit_closure_ = 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 |