OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
Takashi Toyoshima
2014/06/23 08:50:01
I feel now just CldDataHarness is more natural to
Andrew Hayden (chromium.org)
2014/06/23 13:20:35
I like the word "scoped" because it alerts callers
| |
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_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_SCOPED_CLD_DATA_HARNESS_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_TRANSLATE_SCOPED_CLD_DATA_HARNESS_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
9 | 11 |
10 namespace test { | 12 namespace test { |
11 | 13 |
12 // A utility class that sets up CLD dynamic data upon calling Init() and cleans | 14 // A utility class that sets up CLD dynamic data upon calling Init() and cleans |
13 // it up when destroyed. | 15 // it up when destroyed. |
14 // Test data lives under: src/chrome/test/data/cld2_component | 16 // Test data lives under: src/chrome/test/data/cld2_component |
15 // | 17 // |
16 // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F | 18 // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F |
17 // test fixtures; it uses ASSERT macros for correctness, so that tests will | 19 // test fixtures; it uses ASSERT macros for correctness, so that tests will |
18 // fail gracefully in error conditions. Sample use: | 20 // fail gracefully in error conditions. Sample use: |
19 // | 21 // |
20 // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { | 22 // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { |
21 // test::ScopedCLDDynamicDataHarness dynamic_data_scope; | 23 // scoped_ptr<test::ScopedCldDataHarness> cld_data_scope = |
22 // ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); | 24 // test::CreateScopedCldDataHarness(); |
25 // ASSERT_NO_FATAL_FAILURE(cld_data_scope.Init()); | |
23 // // ... your code that depends on language detection goes here | 26 // // ... your code that depends on language detection goes here |
24 // } | 27 // } |
25 // | 28 // |
26 // If you have a lot of tests that need language translation features, you can | 29 // If you have a lot of tests that need language translation features, you can |
27 // add an instance of the ScopedCLDDynamicDataHarness to your test class' | 30 // add an instance of the ScopedCldDataHarness to your test class' private |
28 // private member variables and add the call to Init() into SetUpOnMainThread. | 31 // member variables and add the call to Init() into SetUpOnMainThread. |
29 // Sample use: | 32 // Sample use: |
30 // | 33 // |
31 // class MyTestClass : public InProcessBrowserTest { | 34 // class MyTestClass : public InProcessBrowserTest { |
32 // public: | 35 // public: |
33 // virtual void SetUpOnMainThread() OVERRIDE { | 36 // virtual void SetUpOnMainThread() OVERRIDE { |
34 // dynamic_data_scope.Init(); | 37 // cld_data_scope.Init(); |
35 // InProcessBrowserTest::SetUpOnMainThread(); | 38 // InProcessBrowserTest::SetUpOnMainThread(); |
36 // } | 39 // } |
37 // private: | 40 // private: |
38 // test::ScopedCLDDynamicDataHarness dynamic_data_scope; | 41 // test::ScopedCldDataHarness cld_data_scope; |
39 // }; | 42 // }; |
40 // | 43 // |
41 class ScopedCLDDynamicDataHarness { | 44 class ScopedCldDataHarness { |
42 public: | 45 public: |
43 // Constructs the object, but does nothing. Call Init() to prepare the | |
44 // harness, and enclose that call in ASSERT_NO_FATAL_FAILURE(...). | |
45 ScopedCLDDynamicDataHarness(); | |
46 | |
47 // Reverses the work done by the constructor: any files and/or directories | 46 // Reverses the work done by the constructor: any files and/or directories |
48 // that would be created by the constructor are immediately and irrevocably | 47 // that would be created by the constructor are immediately and irrevocably |
49 // deleted. | 48 // deleted. |
50 // If dynamic data is not currently available for any reason, this method has | 49 // If dynamic data is not currently available for any reason, this method has |
51 // no net effect on the runtime. | 50 // no net effect on the runtime. |
52 ~ScopedCLDDynamicDataHarness(); | 51 virtual ~ScopedCldDataHarness() {} |
53 | 52 |
54 // Call this method, wrapping it in ASSERT_NO_FATAL_FAILURE, to initialize | 53 // Call this method, wrapping it in ASSERT_NO_FATAL_FAILURE, to initialize |
55 // the harness and trigger test failure of initialization fails. | 54 // the harness and trigger test failure if initialization fails. |
56 void Init(); | 55 virtual void Init() = 0; |
57 | 56 |
58 private: | 57 protected: |
Takashi Toyoshima
2014/06/23 08:50:01
Can you add some useful comments on following meth
Andrew Hayden (chromium.org)
2014/06/23 13:20:35
Done.
| |
59 void ClearStandaloneDataFileState(); | 58 const base::FilePath::CharType* GetTestDataSourceCrxVersion(); |
59 void GetTestDataSourceDirectory(base::FilePath* out_path); | |
60 }; | |
60 | 61 |
61 DISALLOW_COPY_AND_ASSIGN(ScopedCLDDynamicDataHarness); | 62 scoped_ptr<ScopedCldDataHarness> CreateScopedCldDataHarness(); |
62 }; | |
63 | 63 |
64 } // namespace test | 64 } // namespace test |
65 | 65 |
66 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ | 66 #endif // CHROME_BROWSER_TRANSLATE_SCOPED_CLD_DATA_HARNESS_H_ |
OLD | NEW |