1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/eye_dropper/eye_dropper.h"
#include <memory>
#include <string>
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/test/test_browser_ui.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/eye_dropper.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "ui/display/display_switches.h"
// TODO(crbug.com/40269208): enable this test on all supported platforms.
#if BUILDFLAG(IS_WIN)
#include "components/eye_dropper/eye_dropper_view.h"
#endif
class EyeDropperBrowserTest : public UiBrowserTest,
public ::testing::WithParamInterface<float> {
public:
EyeDropperBrowserTest() = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
base::NumberToString(GetParam()));
}
// UiBrowserTest:
void ShowUi(const std::string& name) override {
#if BUILDFLAG(IS_WIN)
content::RenderFrameHost* parent_frame = browser()
->tab_strip_model()
->GetActiveWebContents()
->GetPrimaryMainFrame();
parent_frame->GetView()->Focus();
eye_dropper_ = ShowEyeDropper(parent_frame, /*listener=*/nullptr);
#endif
}
bool VerifyUi() override {
#if BUILDFLAG(IS_WIN)
if (!eye_dropper_) {
return false;
}
views::Widget* widget =
static_cast<eye_dropper::EyeDropperView*>(eye_dropper_.get())
->GetWidget();
auto* test_info = testing::UnitTest::GetInstance()->current_test_info();
const std::string screenshot_name =
base::StrCat({test_info->test_suite_name(), "_", test_info->name()});
return VerifyPixelUi(widget, "EyeDropperBrowserTest", screenshot_name) !=
ui::test::ActionResult::kFailed;
#else
return true;
#endif
}
void WaitForUserDismissal() override {
// Consider closing the browser to be dismissal.
ui_test_utils::WaitForBrowserToClose();
}
void DismissUi() override { eye_dropper_.reset(); }
private:
std::unique_ptr<content::EyeDropper> eye_dropper_;
};
// Invokes the eye dropper.
// Flaky: https://crbug.com/40150152, https://crbug.com/402170536
IN_PROC_BROWSER_TEST_P(EyeDropperBrowserTest, DISABLED_InvokeUi_default) {
ShowAndVerifyUi();
}
INSTANTIATE_TEST_SUITE_P(All,
EyeDropperBrowserTest,
testing::Values(1.0, 1.5, 2.0));
|