OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ | |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ | |
7 | |
8 #include "base/macros.h" | |
9 | |
10 namespace test { | |
11 | |
12 // A utility class that sets up CLD dynamic data upon calling Init() and cleans | |
13 // it up when destroyed. | |
14 // | |
15 // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F | |
msw
2014/05/19 18:54:48
Can InProcessBrowserTest subclasses own the Scoped
Andrew Hayden (chromium.org)
2014/05/19 20:54:02
That's certainly a valid pattern. I'll add a note
| |
16 // test fixtures; it uses ASSERT macros for correctness, so that tests will | |
17 // fail gracefully in error conditions. Sample use: | |
18 // | |
19 // #include "chrome/browser/translate/translate_browser_test_utils.h" | |
20 // | |
21 // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { | |
22 // test::ScopedCLDDynamicDataHarness dynamic_data_scope; | |
23 // ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); | |
24 // // ... your code that depends on language detection goes here | |
25 // } | |
26 // | |
27 // NB: Test data lives under src/chrome/test/data/cld2_component | |
28 class ScopedCLDDynamicDataHarness { | |
29 public: | |
30 // Constructs the object, but does nothing. Call Init() to prepare the | |
31 // harness, and enclose that call in ASSERT_NO_FATAL_FAILURE(...). | |
32 ScopedCLDDynamicDataHarness(); | |
33 | |
34 // Reverses the work done by the constructor: any files and/or directories | |
35 // that would be created by the constructor are immediately and irrevocably | |
36 // deleted. | |
37 // If dynamic data is not currently available for any reason, this method has | |
38 // no net effect on the runtime. | |
39 ~ScopedCLDDynamicDataHarness(); | |
40 | |
41 // Call this method, wrapping it in ASSERT_NO_FATAL_FAILURE, to initialize | |
42 // the harness and trigger test failure of initialization fails. | |
43 void Init() OVERRIDE; | |
44 | |
45 private: | |
46 void ClearStandaloneDataFileState(); | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(ScopedCLDDynamicDataHarness); | |
49 }; | |
50 | |
51 } // namespace test | |
52 | |
53 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ | |
OLD | NEW |