Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/webshare/share_service_impl_unittest.cc

Issue 2667803002: Picker takes a vector of pairs, and passes back the user chosen target. (Closed)
Patch Set: Dynamically enable/disable button Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/webshare/share_service_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/webshare/share_service_impl.h" 11 #include "chrome/browser/webshare/share_service_impl.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "mojo/public/cpp/bindings/interface_request.h" 13 #include "mojo/public/cpp/bindings/interface_request.h"
13 #include "mojo/public/cpp/bindings/strong_binding.h" 14 #include "mojo/public/cpp/bindings/strong_binding.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace { 18 namespace {
18 19
19 constexpr char kTitle[] = "My title"; 20 constexpr char kTitle[] = "My title";
20 constexpr char kText[] = "My text"; 21 constexpr char kText[] = "My text";
21 constexpr char kUrlSpec[] = "https://www.google.com/"; 22 constexpr char kUrlSpec[] = "https://www.google.com/";
22 23
23 class ShareServiceTestImpl : public ShareServiceImpl { 24 class ShareServiceTestImpl : public ShareServiceImpl {
24 public: 25 public:
25 static ShareServiceTestImpl* Create( 26 static ShareServiceTestImpl* Create(
26 blink::mojom::ShareServiceRequest request) { 27 blink::mojom::ShareServiceRequest request) {
27 std::unique_ptr<ShareServiceTestImpl> share_service_helper = 28 std::unique_ptr<ShareServiceTestImpl> share_service_helper =
28 base::MakeUnique<ShareServiceTestImpl>(); 29 base::MakeUnique<ShareServiceTestImpl>();
29 ShareServiceTestImpl* share_service_helper_raw = share_service_helper.get(); 30 ShareServiceTestImpl* share_service_helper_raw = share_service_helper.get();
30 mojo::MakeStrongBinding(std::move(share_service_helper), 31 mojo::MakeStrongBinding(std::move(share_service_helper),
31 std::move(request)); 32 std::move(request));
32 return share_service_helper_raw; 33 return share_service_helper_raw;
33 } 34 }
34 35
35 void set_picker_result(SharePickerResult result) { 36 void set_picker_result(base::Optional<std::string> result) {
36 picker_result_ = result; 37 picker_result_ = result;
37 } 38 }
38 39
39 const std::string& GetLastUsedTargetURL() { return last_used_target_url_; } 40 const std::string& GetLastUsedTargetURL() { return last_used_target_url_; }
40 41
41 private: 42 private:
42 SharePickerResult picker_result_ = SharePickerResult::SHARE; 43 base::Optional<std::string> picker_result_;
43 std::string last_used_target_url_; 44 std::string last_used_target_url_;
44 45
45 void ShowPickerDialog( 46 void ShowPickerDialog(
46 const std::vector<base::string16>& targets, 47 const std::vector<std::pair<base::string16, GURL>>& targets,
47 const base::Callback<void(SharePickerResult)>& callback) override { 48 const base::Callback<void(base::Optional<std::string>)>& callback)
49 override {
48 callback.Run(picker_result_); 50 callback.Run(picker_result_);
49 } 51 }
50 52
51 void OpenTargetURL(const GURL& target_url) override { 53 void OpenTargetURL(const GURL& target_url) override {
52 last_used_target_url_ = target_url.spec(); 54 last_used_target_url_ = target_url.spec();
53 } 55 }
54 }; 56 };
55 57
56 class ShareServiceImplUnittest : public ChromeRenderViewHostTestHarness { 58 class ShareServiceImplUnittest : public ChromeRenderViewHostTestHarness {
57 public: 59 public:
(...skipping 27 matching lines...) Expand all
85 87
86 } // namespace 88 } // namespace
87 89
88 // Basic test to check the Share method calls the callback with the expected 90 // Basic test to check the Share method calls the callback with the expected
89 // parameters. 91 // parameters.
90 TEST_F(ShareServiceImplUnittest, ShareCallbackParams) { 92 TEST_F(ShareServiceImplUnittest, ShareCallbackParams) {
91 std::string expected_url = 93 std::string expected_url =
92 "https://wicg.github.io/web-share-target/demos/" 94 "https://wicg.github.io/web-share-target/demos/"
93 "sharetarget.html?title=My%20title&text=My%20text&url=https%3A%2F%2Fwww." 95 "sharetarget.html?title=My%20title&text=My%20text&url=https%3A%2F%2Fwww."
94 "google.com%2F"; 96 "google.com%2F";
97 share_service_helper_->set_picker_result(base::Optional<std::string>(
98 "https://wicg.github.io/web-share-target/demos/"));
95 99
96 const GURL url(kUrlSpec); 100 const GURL url(kUrlSpec);
97 base::Callback<void(const base::Optional<std::string>&)> callback = 101 base::Callback<void(const base::Optional<std::string>&)> callback =
98 base::Bind(&ShareServiceImplUnittest::DidShare, base::Unretained(this), 102 base::Bind(&ShareServiceImplUnittest::DidShare, base::Unretained(this),
99 expected_url, base::Optional<std::string>()); 103 expected_url, base::Optional<std::string>());
100 104
101 base::RunLoop run_loop; 105 base::RunLoop run_loop;
102 on_callback_ = run_loop.QuitClosure(); 106 on_callback_ = run_loop.QuitClosure();
103 107
104 share_service_->Share(kTitle, kText, url, callback); 108 share_service_->Share(kTitle, kText, url, callback);
105 109
106 run_loop.Run(); 110 run_loop.Run();
107 } 111 }
108 112
109 // Tests the result of cancelling the share in the picker UI. 113 // Tests the result of cancelling the share in the picker UI.
110 TEST_F(ShareServiceImplUnittest, ShareCancel) { 114 TEST_F(ShareServiceImplUnittest, ShareCancel) {
111 // Ask that the dialog be cancelled. 115 // picker_result_ is set to nullopt by default, so this imitates the user
112 share_service_helper_->set_picker_result(SharePickerResult::CANCEL); 116 // cancelling a share.
113
114 // Expect an error message in response. 117 // Expect an error message in response.
115 base::Callback<void(const base::Optional<std::string>&)> callback = 118 base::Callback<void(const base::Optional<std::string>&)> callback =
116 base::Bind(&ShareServiceImplUnittest::DidShare, base::Unretained(this), 119 base::Bind(&ShareServiceImplUnittest::DidShare, base::Unretained(this),
117 std::string(), 120 std::string(),
118 base::Optional<std::string>("Share was cancelled")); 121 base::Optional<std::string>("Share was cancelled"));
119 122
120 base::RunLoop run_loop; 123 base::RunLoop run_loop;
121 on_callback_ = run_loop.QuitClosure(); 124 on_callback_ = run_loop.QuitClosure();
122 125
123 const GURL url(kUrlSpec); 126 const GURL url(kUrlSpec);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 EXPECT_TRUE(succeeded); 325 EXPECT_TRUE(succeeded);
323 EXPECT_EQ("%C3%A9", url_template_filled); 326 EXPECT_EQ("%C3%A9", url_template_filled);
324 327
325 // U+1F4A9 328 // U+1F4A9
326 url_template = "{title}"; 329 url_template = "{title}";
327 succeeded = ShareServiceImpl::ReplacePlaceholders( 330 succeeded = ShareServiceImpl::ReplacePlaceholders(
328 url_template, "\xf0\x9f\x92\xa9", kText, url, &url_template_filled); 331 url_template, "\xf0\x9f\x92\xa9", kText, url, &url_template_filled);
329 EXPECT_TRUE(succeeded); 332 EXPECT_TRUE(succeeded);
330 EXPECT_EQ("%F0%9F%92%A9", url_template_filled); 333 EXPECT_EQ("%F0%9F%92%A9", url_template_filled);
331 } 334 }
OLDNEW
« no previous file with comments | « chrome/browser/webshare/share_service_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698