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

Side by Side Diff: chrome/browser/translate/translate_browser_test_utils.h

Issue 296943002: Simplify and extend commenting in test::ScopedCLDDynamicDataHarness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 9
10 namespace test { 10 namespace test {
11 11
12 // A utility class that sets up CLD dynamic data upon calling Init() and cleans 12 // A utility class that sets up CLD dynamic data upon calling Init() and cleans
13 // it up when destroyed. 13 // it up when destroyed.
14 // NB: Test data lives under: src/chrome/test/data/cld2_component
msw 2014/05/22 04:26:48 nit: what does "NB:" itself add to this comment? I
Andrew Hayden (chromium.org) 2014/05/22 10:33:45 Funny thing, I first encountered "NB" about 3 year
14 // 15 //
15 // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F 16 // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F
16 // test fixtures; it uses ASSERT macros for correctness, so that tests will 17 // test fixtures; it uses ASSERT macros for correctness, so that tests will
17 // fail gracefully in error conditions. Sample use: 18 // fail gracefully in error conditions. Sample use:
18 // 19 //
19 // #include "chrome/browser/translate/translate_browser_test_utils.h"
20 //
21 // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { 20 // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) {
22 // test::ScopedCLDDynamicDataHarness dynamic_data_scope; 21 // test::ScopedCLDDynamicDataHarness dynamic_data_scope;
23 // ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); 22 // ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init());
24 // // ... your code that depends on language detection goes here 23 // // ... your code that depends on language detection goes here
25 // } 24 // }
26 // 25 //
27 // If you have a lot of tests that need language translation features, you can 26 // If you have a lot of tests that need language translation features, you can
28 // add an instance of the ScopedCLDDynamicDataHarness to your test class' 27 // add an instance of the ScopedCLDDynamicDataHarness to your test class'
29 // private member variables and add the call to Init() into your Setup method. 28 // private member variables and add the call to Init() into SetUpOnMainThread.
msw 2014/05/22 04:26:48 I'm not sure the example here adds much, in fact I
Andrew Hayden (chromium.org) 2014/05/22 10:33:45 That's fair, I suppose. "git gs ScopedCLD" would g
29 // Sample use:
30 // 30 //
31 // NB: Test data lives under src/chrome/test/data/cld2_component 31 // class MyTestClass : public InProcessBrowserTest {
32 // public:
msw 2014/05/22 04:26:48 nit: remove lines not directly related to init; I'
Andrew Hayden (chromium.org) 2014/05/22 10:33:45 Done.
33 // virtual MyTestClass() {}
34 // virtual ~MyTestclass() {}
35 // virtual void SetUpOnMainThread() OVERRIDE {
36 // dynamic_data_scope.Init();
msw 2014/05/22 04:26:48 If this doesn't need to ASSERT_NO_FATAL_FAILURE(..
Andrew Hayden (chromium.org) 2014/05/22 10:33:45 Thorny question. It doesn't make sense to ASSERT_N
msw 2014/05/22 18:16:58 Thanks for clarifying, I suppose what you have is
37 // InProcessBrowserTest::SetUpOnMainThread();
38 // }
39 // private:
40 // test::ScopedCLDDynamicDataHarness dynamic_data_scope;
41 // DISALLOW_COPY_AND_ASSIGN(MyTestClass);
42 // };
43 //
44 // IN_PROC_BROWSER_TEST_F(MyTestClass, MyTest) {
45 // (your code here)
46 // }
32 class ScopedCLDDynamicDataHarness { 47 class ScopedCLDDynamicDataHarness {
33 public: 48 public:
34 // Constructs the object, but does nothing. Call Init() to prepare the 49 // Constructs the object, but does nothing. Call Init() to prepare the
35 // harness, and enclose that call in ASSERT_NO_FATAL_FAILURE(...). 50 // harness, and enclose that call in ASSERT_NO_FATAL_FAILURE(...).
36 ScopedCLDDynamicDataHarness(); 51 ScopedCLDDynamicDataHarness();
37 52
38 // Reverses the work done by the constructor: any files and/or directories 53 // Reverses the work done by the constructor: any files and/or directories
39 // that would be created by the constructor are immediately and irrevocably 54 // that would be created by the constructor are immediately and irrevocably
40 // deleted. 55 // deleted.
41 // If dynamic data is not currently available for any reason, this method has 56 // If dynamic data is not currently available for any reason, this method has
42 // no net effect on the runtime. 57 // no net effect on the runtime.
43 ~ScopedCLDDynamicDataHarness(); 58 ~ScopedCLDDynamicDataHarness();
44 59
45 // Call this method, wrapping it in ASSERT_NO_FATAL_FAILURE, to initialize 60 // Call this method, wrapping it in ASSERT_NO_FATAL_FAILURE, to initialize
46 // the harness and trigger test failure of initialization fails. 61 // the harness and trigger test failure of initialization fails.
47 void Init(); 62 void Init();
48 63
49 private: 64 private:
50 void ClearStandaloneDataFileState(); 65 void ClearStandaloneDataFileState();
51 66
52 DISALLOW_COPY_AND_ASSIGN(ScopedCLDDynamicDataHarness); 67 DISALLOW_COPY_AND_ASSIGN(ScopedCLDDynamicDataHarness);
53 }; 68 };
54 69
55 } // namespace test 70 } // namespace test
56 71
57 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_ 72 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSER_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698