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

Side by Side Diff: chrome/browser/ui/views/webshare/webshare_target_picker_view_unittest.cc

Issue 2849143002: webshare: Small refactor of WebShare (OnceCallback, const&, and alias) (Closed)
Patch Set: Move alias and use OnceCallback Created 3 years, 7 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/ui/views/webshare/webshare_target_picker_view.h" 5 #include "chrome/browser/ui/views/webshare/webshare_target_picker_view.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 quit_closure_ = base::Closure(); 54 quit_closure_ = base::Closure();
55 constrained_window::SetConstrainedWindowViewsClient(nullptr); 55 constrained_window::SetConstrainedWindowViewsClient(nullptr);
56 56
57 ViewsTestBase::TearDown(); 57 ViewsTestBase::TearDown();
58 } 58 }
59 59
60 protected: 60 protected:
61 // Creates the WebShareTargetPickerView (available as view()). 61 // Creates the WebShareTargetPickerView (available as view()).
62 void CreateView(const std::vector<std::pair<base::string16, GURL>>& targets) { 62 void CreateView(const std::vector<std::pair<base::string16, GURL>>& targets) {
63 view_ = new WebShareTargetPickerView( 63 view_ = new WebShareTargetPickerView(
64 targets, base::Bind(&WebShareTargetPickerViewTest::OnCallback, 64 targets, base::BindOnce(&WebShareTargetPickerViewTest::OnCallback,
65 base::Unretained(this))); 65 base::Unretained(this)));
66 constrained_window::CreateBrowserModalDialogViews( 66 constrained_window::CreateBrowserModalDialogViews(
67 view_, parent_widget_->GetNativeWindow()) 67 view_, parent_widget_->GetNativeWindow())
68 ->Show(); 68 ->Show();
69 } 69 }
70 70
71 // Sets the closure that will be called when the dialog is closed. This is 71 // Sets the closure that will be called when the dialog is closed. This is
72 // used in tests to quit the RunLoop. 72 // used in tests to quit the RunLoop.
73 void SetQuitClosure(base::Closure&& quit_closure) { 73 void SetQuitClosure(base::Closure&& quit_closure) {
74 quit_closure_ = std::move(quit_closure); 74 quit_closure_ = std::move(quit_closure);
75 } 75 }
76 76
77 // The view under test. 77 // The view under test.
78 WebShareTargetPickerView* view() { return view_; } 78 WebShareTargetPickerView* view() { return view_; }
79 // The table inside the view (for inspection). 79 // The table inside the view (for inspection).
80 views::TableView* table() { return view_->table_; } 80 views::TableView* table() { return view_->table_; }
81 81
82 // The result that was returned to the dialog's callback. 82 // The result that was returned to the dialog's callback.
83 const base::Optional<std::string>& result() { return result_; } 83 const base::Optional<std::string>& result() { return result_; }
84 84
85 private: 85 private:
86 void OnCallback(base::Optional<std::string> result) { 86 void OnCallback(const base::Optional<std::string>& result) {
87 result_ = result; 87 result_ = result;
88 if (quit_closure_) 88 if (quit_closure_)
89 quit_closure_.Run(); 89 quit_closure_.Run();
90 } 90 }
91 91
92 std::unique_ptr<views::Widget> parent_widget_; 92 std::unique_ptr<views::Widget> parent_widget_;
93 WebShareTargetPickerView* view_ = nullptr; 93 WebShareTargetPickerView* view_ = nullptr;
94 94
95 base::Optional<std::string> result_; 95 base::Optional<std::string> result_;
96 96
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 base::RunLoop run_loop; 164 base::RunLoop run_loop;
165 SetQuitClosure(run_loop.QuitClosure()); 165 SetQuitClosure(run_loop.QuitClosure());
166 166
167 view()->OnDoubleClick(); 167 view()->OnDoubleClick();
168 168
169 run_loop.Run(); 169 run_loop.Run();
170 170
171 EXPECT_EQ(base::Optional<std::string>("https://appone.com/path/bits"), 171 EXPECT_EQ(base::Optional<std::string>("https://appone.com/path/bits"),
172 result()); 172 result());
173 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698