[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / icon_loader_browsertest.cc
1 // Copyright 2020 The Chromium Authors
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 "base/files/file_path.h"
6 #include "base/path_service.h"
7 #include "base/run_loop.h"
8 #include "build/build_config.h"
9 #include "chrome/browser/icon_loader.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/test/browser_test.h"
12 #include "mojo/public/cpp/bindings/remote.h"
13 #include "ui/gfx/image/image.h"
14
15 #if BUILDFLAG(IS_WIN)
16 #include "ui/display/win/dpi.h"
17 #endif
18
19 using IconLoaderBrowserTest = InProcessBrowserTest;
20
21 class TestIconLoader {
22  public:
23   explicit TestIconLoader(base::OnceClosure quit_closure)
24       : quit_closure_(std::move(quit_closure)) {}
25
26   TestIconLoader(const TestIconLoader&) = delete;
27   TestIconLoader& operator=(const TestIconLoader&) = delete;
28
29   ~TestIconLoader() {
30     if (!quit_closure_.is_null()) {
31       std::move(quit_closure_).Run();
32     }
33   }
34
35   bool load_succeeded() const { return load_succeeded_; }
36
37   bool TryLoadIcon(const base::FilePath& file_path,
38                    IconLoader::IconSize size,
39                    float scale) {
40     IconLoader::LoadIcon(
41         file_path, size, scale,
42         base::BindOnce(&TestIconLoader::OnIconLoaded, base::Unretained(this)));
43     return true;
44   }
45
46  private:
47   void OnIconLoaded(gfx::Image img, const IconLoader::IconGroup& group) {
48     if (!img.IsEmpty())
49       load_succeeded_ = true;
50     Quit();
51   }
52
53   void Quit() {
54     EXPECT_FALSE(quit_closure_.is_null());
55     std::move(quit_closure_).Run();
56   }
57
58   bool load_succeeded_ = false;
59   base::OnceClosure quit_closure_;
60 };
61
62 // Under GTK, the icon providing functions do not return icons.
63 #if !((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && \
64       defined(MEMORY_SANITIZER))
65
66 IN_PROC_BROWSER_TEST_F(IconLoaderBrowserTest, LoadGroup) {
67   float scale = 1.0;
68   constexpr base::FilePath::CharType kGroupOnlyFilename[] =
69       FILE_PATH_LITERAL("unlikely-to-exist-file.txt");
70
71 #if BUILDFLAG(IS_WIN)
72   scale = display::win::GetDPIScale();
73 #endif
74
75   // Test that an icon for a file type (group) can be loaded even
76   // where a file does not exist. Should work cross platform.
77   base::RunLoop runner;
78   TestIconLoader test_loader(runner.QuitClosure());
79   test_loader.TryLoadIcon(base::FilePath(kGroupOnlyFilename),
80                           IconLoader::NORMAL, scale);
81
82   runner.Run();
83   EXPECT_TRUE(test_loader.load_succeeded());
84 }
85
86 #endif  // !((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) &&
87         // defined(MEMORY_SANITIZER))
88
89 #if BUILDFLAG(IS_WIN)
90 IN_PROC_BROWSER_TEST_F(IconLoaderBrowserTest, LoadExeIcon) {
91   float scale = display::win::GetDPIScale();
92   base::RunLoop runner;
93
94   TestIconLoader test_loader(runner.QuitClosure());
95
96   base::FilePath exe_path;
97   base::PathService::Get(base::FILE_EXE, &exe_path);
98   test_loader.TryLoadIcon(exe_path, IconLoader::NORMAL, scale);
99
100   runner.Run();
101   EXPECT_TRUE(test_loader.load_succeeded());
102 }
103
104 const base::FilePath::CharType kNotExistingExeFile[] =
105     FILE_PATH_LITERAL("unlikely-to-exist-file.exe");
106
107 IN_PROC_BROWSER_TEST_F(IconLoaderBrowserTest, LoadDefaultExeIcon) {
108   float scale = display::win::GetDPIScale();
109
110   base::RunLoop runner;
111
112   TestIconLoader test_loader(runner.QuitClosure());
113
114   test_loader.TryLoadIcon(base::FilePath(kNotExistingExeFile),
115                           IconLoader::NORMAL, scale);
116
117   runner.Run();
118   EXPECT_TRUE(test_loader.load_succeeded());
119 }
120 #endif  // BUILDFLAG(IS_WIN)