Chromium Code Reviews| Index: chrome/browser/ui/views/webshare/webshare_target_picker_view_unittest.cc |
| diff --git a/chrome/browser/ui/views/webshare/webshare_target_picker_view_unittest.cc b/chrome/browser/ui/views/webshare/webshare_target_picker_view_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9895e452c27a6ed34636ce006e603c7de051a235 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/webshare/webshare_target_picker_view_unittest.cc |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2017 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 <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/run_loop.h" |
| +#include "base/strings/string16.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#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.
|
| +#include "chrome/test/base/browser_with_test_window_test.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/views/controls/table/table_view.h" |
| +#include "ui/views/window/dialog_client_view.h" |
| +#include "ui/views/window/dialog_delegate.h" |
| + |
| +namespace { |
| + |
| +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
|
| + public: |
| + void SetUp() override { |
| + ChromeRenderViewHostTestHarness::SetUp(); |
| + } |
| + |
| + void TearDown() override { |
| + ChromeRenderViewHostTestHarness::TearDown(); |
| + view_.reset(); |
| + quit_closure_ = base::Closure(); |
| + } |
| + |
| + protected: |
| + // Creates the WebShareTargetPickerView (available as view()). |
| + void CreateView(const std::vector<base::string16>& targets) { |
| + view_.reset(new WebShareTargetPickerView( |
| + targets, base::Bind(&WebShareTargetPickerViewTest::callback, |
| + base::Unretained(this)))); |
| + } |
| + |
| + // Sets the closure that will be called when the dialog is closed. This is |
| + // used in tests to quit the RunLoop. |
| + void SetQuitClosure(base::Closure&& quit_closure) { |
| + quit_closure_ = std::move(quit_closure); |
| + } |
| + |
| + // The view under test. |
| + WebShareTargetPickerView* view() { return view_.get(); } |
| + // The table inside the view (for inspection). |
| + views::TableView* table() { return view_->table_; } |
| + |
| + // The result that was returned to the dialog's callback. |
| + SharePickerResult result() { return result_; } |
| + |
| + private: |
| + void callback(SharePickerResult result) { |
|
sky
2017/02/06 17:11:24
OnCallback?
Matt Giuca
2017/02/06 23:17:21
Done.
|
| + result_ = result; |
| + if (quit_closure_) |
| + quit_closure_.Run(); |
| + } |
| + |
| + std::unique_ptr<WebShareTargetPickerView> view_; |
| + |
| + SharePickerResult result_; |
| + |
| + base::Closure quit_closure_; |
| +}; |
|
sky
2017/02/06 17:11:24
DISALLOW...
Matt Giuca
2017/02/06 23:17:22
Done.
|
| + |
| +// Table with 0 targets. Choose to cancel. |
| +TEST_F(WebShareTargetPickerViewTest, EmptyListCancel) { |
| + CreateView(std::vector<base::string16>()); |
| + EXPECT_EQ(0, table()->RowCount()); |
| + |
| + view()->Cancel(); |
| + |
| + base::RunLoop run_loop; |
| + SetQuitClosure(run_loop.QuitClosure()); |
| + |
| + EXPECT_EQ(SharePickerResult::CANCEL, result()); |
| +} |
| + |
| +// Table with 2 targets. Choose second target and share. |
| +TEST_F(WebShareTargetPickerViewTest, ChooseItem) { |
| + std::vector<base::string16> targets{base::ASCIIToUTF16("App One"), |
| + base::ASCIIToUTF16("App Two")}; |
| + CreateView(targets); |
| + EXPECT_EQ(2, table()->RowCount()); |
| + EXPECT_EQ(base::ASCIIToUTF16("App One"), table()->model()->GetText(0, 0)); |
| + EXPECT_EQ(base::ASCIIToUTF16("App Two"), table()->model()->GetText(1, 0)); |
| + |
| + // Choose the second app. |
| + table()->Select(1); |
| + view()->Accept(); |
| + |
| + base::RunLoop run_loop; |
| + SetQuitClosure(run_loop.QuitClosure()); |
| + |
| + EXPECT_EQ(SharePickerResult::SHARE, result()); |
| +} |
| + |
| +} // namespace |