File: eye_dropper_browsertest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (87 lines) | stat: -rw-r--r-- 2,949 bytes parent folder | download | duplicates (3)
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));