Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/chromeos/login/screenshot_tester.h

Issue 433873002: Loading screenshots and simple 1-to-1 comparison of screenshots (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "switch files updated" Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTER_H_
7 7
8 #include <string>
9
8 #include "base/base_export.h" 10 #include "base/base_export.h"
9 #include "base/bind_internal.h" 11 #include "base/bind_internal.h"
10 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
13 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
14 #include "base/run_loop.h" 16 #include "base/run_loop.h"
15 17
16 namespace chromeos { 18 namespace chromeos {
17 19
18 // A class that allows taking, saving and comparing screnshots while 20 // A class that allows taking, saving and comparing screnshots while
19 // running tests. 21 // running tests.
20 class ScreenshotTester { 22 class ScreenshotTester {
21 public: 23 public:
22 ScreenshotTester(); 24 ScreenshotTester();
23 virtual ~ScreenshotTester(); 25 virtual ~ScreenshotTester();
24 26
25 // Returns true if the screenshots should be taken and will be taken, 27 // Returns true if the screenshots should be taken and will be taken,
26 // false otherwise. Also gets all the information from the command line 28 // false otherwise. Also gets all the information from the command line
27 // swithes. 29 // swithes.
28 bool TryInitialize(); 30 bool TryInitialize();
29 31
30 // Does all the work that has been stated through switches: 32 // Does all the work that has been stated through switches:
31 // updates golden screenshot or takes a new screenshot and compares it 33 // updates golden screenshot or takes a new screenshot and compares it
32 // with the golden one (this part is not implemented yet). 34 // with the golden one. |test_name| is the name of the test from which
33 void Run(const std::string& file_name); 35 // we run this method.
36 void Run(const std::string& test_name);
34 37
35 private: 38 private:
36 typedef scoped_refptr<base::RefCountedBytes> PNGFile; 39 typedef scoped_refptr<base::RefCountedBytes> PNGFile;
37 40
38 // Takes a screenshot and puts it to |screenshot_| field. 41 // Takes a screenshot and returns it.
39 void TakeScreenshot(); 42 PNGFile TakeScreenshot();
40 43
41 // Saves |png_data| as a new golden screenshot for this test. 44 // Saves |png_data| as a new golden screenshot for test |test_name_|.
42 void UpdateGoldenScreenshot(const std::string& file_name, PNGFile png_data); 45 void UpdateGoldenScreenshot(PNGFile png_data);
46
47 // Saves an image |png_data|, assuming it is a .png file.
48 void SaveImage(const std::string& file_name,
49 const base::FilePath& screenshot_dir,
50 PNGFile png_data);
43 51
44 // Saves |png_data| as a current screenshot. 52 // Saves |png_data| as a current screenshot.
45 void ReturnScreenshot(PNGFile png_data); 53 void ReturnScreenshot(const PNGFile& screenshot, PNGFile png_data);
54
55 // Loads golden screenshot from the disk. Fails if there is no
56 // golden screenshot for test |test_name_|.
57 PNGFile LoadGoldenScreenshot();
58
59 // Compares two given screenshots and saves |sample|
60 // and difference between |sample| and |model|, if they differ in any pixel.
61 void CompareScreenshots(PNGFile model, PNGFile sample);
62
63 // Name of the test from which Run() method has been called.
64 // Used for generating names for screenshot files.
65 std::string test_name_;
46 66
47 // Path to the directory for golden screenshots. 67 // Path to the directory for golden screenshots.
48 base::FilePath screenshot_dest_; 68 base::FilePath golden_screenshots_dir_;
69
70 // Path to the directory where screenshots that failed comparing
71 // and difference between them and golden ones will be stored.
72 base::FilePath artifacts_dir_;
49 73
50 // |run_loop_| and |run_loop_quitter_| are used to synchronize 74 // |run_loop_| and |run_loop_quitter_| are used to synchronize
51 // with ui::GrabWindowSnapshotAsync. 75 // with ui::GrabWindowSnapshotAsync.
52 base::RunLoop run_loop_; 76 base::RunLoop run_loop_;
53 base::Closure run_loop_quitter_; 77 base::Closure run_loop_quitter_;
54 78
55 // Current screenshot. 79 // Is true when we're in test mode:
56 PNGFile screenshot_; 80 // comparing golden screenshots and current ones.
81 bool test_mode_;
57 82
58 // Is true when we running updating golden screenshots mode.
59 bool update_golden_screenshot_;
60 base::WeakPtrFactory<ScreenshotTester> weak_factory_; 83 base::WeakPtrFactory<ScreenshotTester> weak_factory_;
61 84
62 DISALLOW_COPY_AND_ASSIGN(ScreenshotTester); 85 DISALLOW_COPY_AND_ASSIGN(ScreenshotTester);
63 }; 86 };
64 87
65 } // namespace chromeos 88 } // namespace chromeos
66 89
67 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTER_H_ 90 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENSHOT_TESTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698