Chromium Code Reviews| Index: chrome/browser/webshare/share_service_impl_unittest.cc |
| diff --git a/chrome/browser/webshare/share_service_impl_unittest.cc b/chrome/browser/webshare/share_service_impl_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..884f97581dc0a779641677003b5f400c3e89cdc3 |
| --- /dev/null |
| +++ b/chrome/browser/webshare/share_service_impl_unittest.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/run_loop.h" |
| +#include "chrome/browser/webshare/share_service_impl.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| +#include "mojo/public/cpp/bindings/interface_request.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "url/gurl.h" |
| + |
| +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
|
| + public: |
| + ShareServiceTest() {} |
|
Sam McNally
2016/12/09 04:23:45
= default;
constantina
2016/12/12 02:50:33
Done.
|
| + ~ShareServiceTest() override {} |
|
Sam McNally
2016/12/09 04:23:45
= default;
constantina
2016/12/12 02:50:32
Done.
|
| + |
| + void SetUp() override { |
| + ChromeRenderViewHostTestHarness::SetUp(); |
| + |
| + ShareServiceImpl::Create(mojo::GetProxy(&share_service_)); |
| + } |
| + |
| + 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.
|
| + const base::Optional<std::string>& str) { |
| + EXPECT_EQ(expected, str); |
| + |
| + if (!on_callback_.is_null()) |
| + on_callback_.Run(); |
| + } |
| + |
| + blink::mojom::ShareServicePtr share_service_; |
| + base::Closure on_callback_; |
| +}; |
| + |
| +// Basic test to check the Share method uses the callback as expected. |
| +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
|
| + const GURL url("https://www.google.com"); |
| + |
| + base::RunLoop run_loop; |
| + on_callback_ = run_loop.QuitClosure(); |
| + |
| + base::Callback<void(const base::Optional<std::string>&)> callback = |
| + base::Bind( |
| + &ShareServiceTest::callback, base::Unretained(this), |
| + base::Optional<std::string>("Not implemented: navigator.share")); |
| + share_service_->Share("title", "text", url, callback); |
| + |
| + run_loop.Run(); |
| +} |