Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <vector> | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "base/strings/string16.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "chrome/browser/ui/views/webshare/webshare_target_picker_view.h" | |
|
sky
2017/02/06 17:11:24
This should be your first include (just like web_s
Matt Giuca
2017/02/06 23:17:22
Done.
| |
| 13 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "ui/views/controls/table/table_view.h" | |
| 17 #include "ui/views/window/dialog_client_view.h" | |
| 18 #include "ui/views/window/dialog_delegate.h" | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 class WebShareTargetPickerViewTest : public ChromeRenderViewHostTestHarness { | |
|
sky
2017/02/06 17:11:24
Based on capitalization all of the files in this d
Matt Giuca
2017/02/06 23:17:22
Hmm, that's a good point, but we have directories
| |
| 23 public: | |
| 24 void SetUp() override { | |
| 25 ChromeRenderViewHostTestHarness::SetUp(); | |
| 26 } | |
| 27 | |
| 28 void TearDown() override { | |
| 29 ChromeRenderViewHostTestHarness::TearDown(); | |
| 30 view_.reset(); | |
| 31 quit_closure_ = base::Closure(); | |
| 32 } | |
| 33 | |
| 34 protected: | |
| 35 // Creates the WebShareTargetPickerView (available as view()). | |
| 36 void CreateView(const std::vector<base::string16>& targets) { | |
| 37 view_.reset(new WebShareTargetPickerView( | |
| 38 targets, base::Bind(&WebShareTargetPickerViewTest::callback, | |
| 39 base::Unretained(this)))); | |
| 40 } | |
| 41 | |
| 42 // Sets the closure that will be called when the dialog is closed. This is | |
| 43 // used in tests to quit the RunLoop. | |
| 44 void SetQuitClosure(base::Closure&& quit_closure) { | |
| 45 quit_closure_ = std::move(quit_closure); | |
| 46 } | |
| 47 | |
| 48 // The view under test. | |
| 49 WebShareTargetPickerView* view() { return view_.get(); } | |
| 50 // The table inside the view (for inspection). | |
| 51 views::TableView* table() { return view_->table_; } | |
| 52 | |
| 53 // The result that was returned to the dialog's callback. | |
| 54 SharePickerResult result() { return result_; } | |
| 55 | |
| 56 private: | |
| 57 void callback(SharePickerResult result) { | |
|
sky
2017/02/06 17:11:24
OnCallback?
Matt Giuca
2017/02/06 23:17:21
Done.
| |
| 58 result_ = result; | |
| 59 if (quit_closure_) | |
| 60 quit_closure_.Run(); | |
| 61 } | |
| 62 | |
| 63 std::unique_ptr<WebShareTargetPickerView> view_; | |
| 64 | |
| 65 SharePickerResult result_; | |
| 66 | |
| 67 base::Closure quit_closure_; | |
| 68 }; | |
|
sky
2017/02/06 17:11:24
DISALLOW...
Matt Giuca
2017/02/06 23:17:22
Done.
| |
| 69 | |
| 70 // Table with 0 targets. Choose to cancel. | |
| 71 TEST_F(WebShareTargetPickerViewTest, EmptyListCancel) { | |
| 72 CreateView(std::vector<base::string16>()); | |
| 73 EXPECT_EQ(0, table()->RowCount()); | |
| 74 | |
| 75 view()->Cancel(); | |
| 76 | |
| 77 base::RunLoop run_loop; | |
| 78 SetQuitClosure(run_loop.QuitClosure()); | |
| 79 | |
| 80 EXPECT_EQ(SharePickerResult::CANCEL, result()); | |
| 81 } | |
| 82 | |
| 83 // Table with 2 targets. Choose second target and share. | |
| 84 TEST_F(WebShareTargetPickerViewTest, ChooseItem) { | |
| 85 std::vector<base::string16> targets{base::ASCIIToUTF16("App One"), | |
| 86 base::ASCIIToUTF16("App Two")}; | |
| 87 CreateView(targets); | |
| 88 EXPECT_EQ(2, table()->RowCount()); | |
| 89 EXPECT_EQ(base::ASCIIToUTF16("App One"), table()->model()->GetText(0, 0)); | |
| 90 EXPECT_EQ(base::ASCIIToUTF16("App Two"), table()->model()->GetText(1, 0)); | |
| 91 | |
| 92 // Choose the second app. | |
| 93 table()->Select(1); | |
| 94 view()->Accept(); | |
| 95 | |
| 96 base::RunLoop run_loop; | |
| 97 SetQuitClosure(run_loop.QuitClosure()); | |
| 98 | |
| 99 EXPECT_EQ(SharePickerResult::SHARE, result()); | |
| 100 } | |
| 101 | |
| 102 } // namespace | |
| OLD | NEW |