Home | History | Annotate | Download | only in test
      1 // Copyright (c) 2011 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/test/test_timeouts.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/logging.h"
      9 #include "base/string_number_conversions.h"
     10 #include "base/test/test_switches.h"
     11 
     12 namespace {
     13 
     14 // Sets value to the greatest of:
     15 // 1) value's current value.
     16 // 2) min_value.
     17 // 3) the numerical value given by switch_name on the command line.
     18 void InitializeTimeout(const char* switch_name, int min_value, int* value) {
     19   DCHECK(value);
     20   if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
     21     std::string string_value(
     22         CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name));
     23     int timeout;
     24     base::StringToInt(string_value, &timeout);
     25     *value = std::max(*value, timeout);
     26   }
     27   *value = std::max(*value, min_value);
     28 }
     29 
     30 // Sets value to the greatest of:
     31 // 1) value's current value.
     32 // 2) 0
     33 // 3) the numerical value given by switch_name on the command line.
     34 void InitializeTimeout(const char* switch_name, int* value) {
     35   InitializeTimeout(switch_name, 0, value);
     36 }
     37 
     38 }  // namespace
     39 
     40 // static
     41 bool TestTimeouts::initialized_ = false;
     42 
     43 // The timeout values should increase in the order they appear in this block.
     44 // static
     45 int TestTimeouts::tiny_timeout_ms_ = 100;
     46 int TestTimeouts::action_timeout_ms_ = 2000;
     47 int TestTimeouts::action_max_timeout_ms_ = 25000;
     48 int TestTimeouts::large_test_timeout_ms_ = 3 * 60 * 1000;
     49 int TestTimeouts::huge_test_timeout_ms_ = 10 * 60 * 1000;
     50 
     51 // static
     52 int TestTimeouts::wait_for_terminate_timeout_ms_ = 15000;
     53 
     54 // static
     55 int TestTimeouts::live_operation_timeout_ms_ = 45000;
     56 
     57 // static
     58 void TestTimeouts::Initialize() {
     59   if (initialized_) {
     60     NOTREACHED();
     61     return;
     62   }
     63   initialized_ = true;
     64 
     65   // Note that these timeouts MUST be initialized in the correct order as
     66   // per the CHECKS below.
     67   InitializeTimeout(switches::kTestTinyTimeout, &tiny_timeout_ms_);
     68   InitializeTimeout(switches::kUiTestActionTimeout, tiny_timeout_ms_,
     69                     &action_timeout_ms_);
     70   InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_,
     71                     &action_max_timeout_ms_);
     72   InitializeTimeout(switches::kTestLargeTimeout, action_max_timeout_ms_,
     73                     &large_test_timeout_ms_);
     74   InitializeTimeout(switches::kUiTestTimeout, large_test_timeout_ms_,
     75                     &huge_test_timeout_ms_);
     76 
     77   // The timeout values should be increasing in the right order.
     78   CHECK(tiny_timeout_ms_ <= action_timeout_ms_);
     79   CHECK(action_timeout_ms_ <= action_max_timeout_ms_);
     80   CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_);
     81   CHECK(large_test_timeout_ms_ <= huge_test_timeout_ms_);
     82 
     83   InitializeTimeout(switches::kUiTestTerminateTimeout,
     84                     &wait_for_terminate_timeout_ms_);
     85 
     86   InitializeTimeout(switches::kLiveOperationTimeout,
     87                     &live_operation_timeout_ms_);
     88 }
     89