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 "chrome/browser/ui/views/extensions/chooser_dialog_view.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "chrome/browser/chooser_controller/mock_chooser_controller.h" | |
| 12 #include "chrome/browser/platform_util.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 15 #include "chrome/browser/ui/test/test_browser_dialog.h" | |
| 16 #include "components/constrained_window/constrained_window_views.h" | |
| 17 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 18 | |
| 19 // Invokes the device chooser dialog with mock content. See | |
| 20 // test_browser_dialog.h. | |
| 21 class ChooserDialogViewBrowserTest : public DialogBrowserTest { | |
| 22 public: | |
| 23 ChooserDialogViewBrowserTest() : controller_(new MockChooserController()) {} | |
| 24 | |
| 25 // DialogBrowserTest: | |
| 26 void ShowDialog(const std::string& name) override { | |
| 27 auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 28 web_modal::WebContentsModalDialogManager* manager = | |
| 29 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | |
| 30 if (manager) { | |
| 31 constrained_window::ShowWebModalDialogViews( | |
| 32 new ChooserDialogView(std::move(controller_)), web_contents); | |
|
Peter Kasting
2017/06/12 22:36:51
This doesn't leak, does it? It was hard for me to
Bret
2017/06/13 21:53:30
It doesn't leak, the delegate is owned by the Widg
| |
| 33 } | |
| 34 } | |
| 35 | |
| 36 MockChooserController& controller() { return *controller_; } | |
| 37 | |
| 38 private: | |
| 39 std::unique_ptr<MockChooserController> controller_; | |
|
Peter Kasting
2017/06/12 22:36:51
Nit: Why not own this by value instead of pointer?
Bret
2017/06/13 21:53:30
We transfer ownership to ChooserDialogView once th
| |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(ChooserDialogViewBrowserTest); | |
| 42 }; | |
| 43 | |
| 44 IN_PROC_BROWSER_TEST_F(ChooserDialogViewBrowserTest, InvokeDialog_noDevices) { | |
| 45 RunDialog(); | |
| 46 } | |
| 47 | |
| 48 IN_PROC_BROWSER_TEST_F(ChooserDialogViewBrowserTest, InvokeDialog_withDevices) { | |
| 49 controller().OptionAdded(base::ASCIIToUTF16("Device 1"), | |
| 50 MockChooserController::kNoSignalStrengthLevelImage, | |
| 51 MockChooserController::NONE); | |
| 52 controller().OptionAdded(base::ASCIIToUTF16("Device 2"), | |
| 53 MockChooserController::kSignalStrengthLevel2Bar, | |
| 54 MockChooserController::PAIRED); | |
| 55 controller().OptionAdded(base::ASCIIToUTF16("Device 3"), | |
| 56 MockChooserController::kSignalStrengthLevel4Bar, | |
| 57 MockChooserController::CONNECTED); | |
| 58 controller().OptionAdded( | |
| 59 base::ASCIIToUTF16("Device 4"), | |
| 60 MockChooserController::kSignalStrengthLevel1Bar, | |
| 61 MockChooserController::PAIRED | MockChooserController::CONNECTED); | |
| 62 RunDialog(); | |
| 63 } | |
| OLD | NEW |