OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "base/command_line.h" | |
6 #include "build/build_config.h" | |
7 #include "chrome/browser/ui/test/test_browser_dialog.h" | |
8 #include "chrome/common/chrome_result_codes.h" | |
9 #include "chrome/common/chrome_switches.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | |
11 #include "ui/base/ui_base_switches.h" | |
12 | |
13 // Unfortunately, this needs to be Windows only for now. Even though this test | |
14 // is meant to exercise code that is for Windows only, it is a good general | |
15 // canary in the coal mine for problems related to early shutdown (aborted | |
16 // startup). Sadly, it times out on platforms other than Windows, so I can't | |
17 // enable it for those platforms at the moment. I hope one day our test harness | |
18 // will be improved to support this so we can get coverage on other platforms. | |
19 // See http://crbug.com/45115 for details. | |
20 #if defined(OS_WIN) | |
21 #include "chrome/browser/ui/views/try_chrome_dialog_view.h" | |
22 | |
23 // By passing kTryChromeAgain with a magic value > 10000 we cause Chrome | |
24 // to exit fairly early. | |
25 // Quickly exiting Chrome (regardless of this particular flag -- it | |
26 // doesn't do anything other than cause Chrome to quit on startup on | |
27 // non-Windows) was a cause of crashes (see bug 34799 for example) so | |
28 // this is a useful test of the startup/quick-shutdown cycle. | |
29 class TryChromeDialogBrowserTest : public InProcessBrowserTest { | |
30 public: | |
31 TryChromeDialogBrowserTest() { | |
32 set_expected_exit_code(chrome::RESULT_CODE_NORMAL_EXIT_CANCEL); | |
33 } | |
34 | |
35 protected: | |
36 void SetUpCommandLine(base::CommandLine* command_line) override { | |
37 command_line->AppendSwitchASCII(switches::kTryChromeAgain, "10001"); | |
38 } | |
39 }; | |
40 | |
41 // Note to Sheriffs: This test (as you can read about above) simply causes | |
42 // Chrome to shutdown early, and, as such, has proven to be pretty good at | |
43 // finding problems related to shutdown. Sheriff, before marking this test as | |
44 // disabled, please consider that this test is meant to catch when people | |
45 // introduce changes that crash Chrome during shutdown and disabling this test | |
46 // and moving on removes a safeguard meant to avoid an even bigger thorny mess | |
47 // to untangle much later down the line. Disabling the test also means that the | |
48 // people who get blamed are not the ones that introduced the crash (in other | |
49 // words, don't shoot the messenger). So, please help us avoid additional | |
50 // shutdown crashes from creeping in, by doing the following: | |
51 // Run chrome.exe --try-chrome-again=10001. This is all that the test does and | |
52 // should be enough to trigger the failure. If it is a crash (most likely) then | |
53 // look at the callstack and see if any of the components have been touched | |
54 // recently. Look at recent changes to startup, such as any change to | |
55 // ChromeBrowserMainParts, specifically PreCreateThreadsImpl and see if someone | |
56 // has been reordering code blocks for startup. Try reverting any suspicious | |
57 // changes to see if it affects the test. History shows that waiting until later | |
58 // only makes the problem worse. | |
59 IN_PROC_BROWSER_TEST_F(TryChromeDialogBrowserTest, ToastCrasher) {} | |
60 | |
61 // Helper class to display the TryChromeDialog for testing. | |
62 class TryChromeDialogTest : public DialogBrowserTest { | |
63 public: | |
64 // TODO(ananta) | |
65 // Provide a way to test flavors other than 0. | |
66 TryChromeDialogTest() : dialog_(0) {} | |
67 | |
68 static void DialogHandler(gfx::NativeWindow active_dialog) {} | |
69 | |
70 // DialogBrowserTest: | |
71 void ShowDialog(const std::string& name) override { | |
72 dialog_.ShowDialog(base::Bind(&TryChromeDialogTest::DialogHandler), | |
73 TryChromeDialogView::kDialogType::MODELESS, | |
74 TryChromeDialogView::kUsageType::FOR_TESTING); | |
75 } | |
76 | |
77 // content::BrowserTestBase: | |
78 void SetUpCommandLine(base::CommandLine* command_line) override { | |
79 command_line->AppendSwitch(switches::kExtendMdToSecondaryUi); | |
80 } | |
81 | |
82 private: | |
83 TryChromeDialogView dialog_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(TryChromeDialogTest); | |
86 }; | |
87 | |
88 IN_PROC_BROWSER_TEST_F(TryChromeDialogTest, InvokeDialog_default) { | |
89 RunDialog(); | |
90 } | |
91 | |
92 #endif // defined(OS_WIN) | |
OLD | NEW |