diff options
author | pathorn@chromium.org <pathorn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 03:03:03 +0000 |
---|---|---|
committer | pathorn@chromium.org <pathorn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 03:03:03 +0000 |
commit | f7d992aa311c3cec1fc95ce06338b129f4b34cbe (patch) | |
tree | 82635eaa7af26fdf14b52602e03b8803a8beda75 /chrome/test/automation/browser_proxy.cc | |
parent | f7d23eb77d60e8a01edd1b48e2a2fa38dad4dde2 (diff) | |
download | chromium_src-f7d992aa311c3cec1fc95ce06338b129f4b34cbe.zip chromium_src-f7d992aa311c3cec1fc95ce06338b129f4b34cbe.tar.gz chromium_src-f7d992aa311c3cec1fc95ce06338b129f4b34cbe.tar.bz2 |
Make new startup test use GetInitialLoadTimes for more accurate times.
This change modifies RunStartupTest to call GetInitialLoadTimes, if applicable, to print out additional statistics for each tab computed on the browser.
Additionally, changes |test_cold| and |important| parameters to be enums instead of booleans to make tests more readable.
BUG=44129
TEST=none
Review URL: http://codereview.chromium.org/2714015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation/browser_proxy.cc')
-rw-r--r-- | chrome/test/automation/browser_proxy.cc | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc index 1b275d8..5b5efca 100644 --- a/chrome/test/automation/browser_proxy.cc +++ b/chrome/test/automation/browser_proxy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,8 @@ #include <vector> +#include "base/json/json_reader.h" +#include "base/json/json_writer.h" #include "base/logging.h" #include "base/platform_thread.h" #include "base/time.h" @@ -594,3 +596,63 @@ bool BrowserProxy::SendJSONRequest(const std::string& request, &result)); return result; } + +bool BrowserProxy::GetInitialLoadTimes(float* min_start_time, + float* max_stop_time, + std::vector<float>* stop_times) { + std::string json_response; + const char* kJSONCommand = "{\"command\": \"GetInitialLoadTimes\"}"; + + *max_stop_time = 0; + *min_start_time = -1; + if (!SendJSONRequest(kJSONCommand, &json_response)) { + // Older browser versions do not support GetInitialLoadTimes. + // Fail gracefully and do not record them in this case. + return false; + } + std::string error; + base::JSONReader reader; + scoped_ptr<Value> values(reader.ReadAndReturnError(json_response, true, + NULL, &error)); + if (!error.empty() || values->GetType() != Value::TYPE_DICTIONARY) + return false; + + DictionaryValue* values_dict = static_cast<DictionaryValue*>(values.get()); + + Value* tabs_value; + if (!values_dict->Get(L"tabs", &tabs_value) || + tabs_value->GetType() != Value::TYPE_LIST) + return false; + + ListValue* tabs_list = static_cast<ListValue*>(tabs_value); + + for (size_t i = 0; i < tabs_list->GetSize(); i++) { + float stop_ms = 0; + float start_ms = 0; + Value* tab_value; + DictionaryValue* tab_dict; + + if (!tabs_list->Get(i, &tab_value) || + tab_value->GetType() != Value::TYPE_DICTIONARY) + return false; + tab_dict = static_cast<DictionaryValue*>(tab_value); + + double temp; + if (!tab_dict->GetReal(L"load_start_ms", &temp)) + return false; + start_ms = static_cast<float>(temp); + // load_stop_ms can only be null if WaitForInitialLoads did not run. + if (!tab_dict->GetReal(L"load_stop_ms", &temp)) + return false; + stop_ms = static_cast<float>(temp); + + if (i == 0) + *min_start_time = start_ms; + + *min_start_time = std::min(start_ms, *min_start_time); + *max_stop_time = std::max(stop_ms, *max_stop_time); + stop_times->push_back(stop_ms); + } + std::sort(stop_times->begin(), stop_times->end()); + return true; +} |