15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/common/chrome_result_codes.h"
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Unfortunately, this needs to be Windows only for now. Even though this test
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is meant to exercise code that is for Windows only, it is a good general
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// canary in the coal mine for problems related to early shutdown (aborted
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// startup). Sadly, it times out on platforms other than Windows, so I can't
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// enable it for those platforms at the moment. I hope one day our test harness
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// will be improved to support this so we can get coverage on other platforms.
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See http://crbug.com/45115 for details.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// By passing kTryChromeAgain with a magic value > 10000 we cause Chrome
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to exit fairly early.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Quickly exiting Chrome (regardless of this particular flag -- it
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// doesn't do anything other than cause Chrome to quit on startup on
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// non-Windows) was a cause of crashes (see bug 34799 for example) so
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this is a useful test of the startup/quick-shutdown cycle.
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TryChromeDialogBrowserTest : public InProcessBrowserTest {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
2746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  TryChromeDialogBrowserTest() {
2846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    set_expected_exit_code(chrome::RESULT_CODE_NORMAL_EXIT_CANCEL);
2946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)protected:
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    command_line->AppendSwitchASCII(switches::kTryChromeAgain, "10001");
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note to Sheriffs: This test (as you can read about above) simply causes
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Chrome to shutdown early, and, as such, has proven to be pretty good at
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// finding problems related to shutdown. Sheriff, before marking this test as
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// disabled, please consider that this test is meant to catch when people
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// introduce changes that crash Chrome during shutdown and disabling this test
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and moving on removes a safeguard meant to avoid an even bigger thorny mess
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to untangle much later down the line. Disabling the test also means that the
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// people who get blamed are not the ones that introduced the crash (in other
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// words, don't shoot the messenger). So, please help us avoid additional
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// shutdown crashes from creeping in, by doing the following:
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Run chrome.exe --try-chrome-again=10001. This is all that the test does and
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// should be enough to trigger the failure. If it is a crash (most likely) then
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// look at the callstack and see if any of the components have been touched
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// recently. Look at recent changes to startup, such as any change to
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ChromeBrowserMainParts, specifically PreCreateThreadsImpl and see if someone
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// has been reordering code blocks for startup. Try reverting any suspicious
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// changes to see if it affects the test. History shows that waiting until later
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// only makes the problem worse.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(TryChromeDialogBrowserTest, ToastCrasher) {}
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_WIN)
58