| 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 <string> | |
| 6 | |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/test/chromedriver/frame_tracker.h" | |
| 10 #include "chrome/test/chromedriver/status.h" | |
| 11 #include "chrome/test/chromedriver/stub_devtools_client.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 TEST(FrameTracker, GetContextIdForFrame) { | |
| 15 StubDevToolsClient client; | |
| 16 FrameTracker tracker(&client); | |
| 17 int context_id = -1; | |
| 18 ASSERT_TRUE(tracker.GetContextIdForFrame("f", &context_id).IsError()); | |
| 19 ASSERT_EQ(-1, context_id); | |
| 20 | |
| 21 const char context[] = "{\"id\":100,\"frameId\":\"f\"}"; | |
| 22 base::DictionaryValue params; | |
| 23 params.Set("context", base::JSONReader::Read(context)); | |
| 24 tracker.OnEvent("Runtime.executionContextCreated", params); | |
| 25 ASSERT_TRUE(tracker.GetContextIdForFrame("foo", &context_id).IsError()); | |
| 26 ASSERT_EQ(-1, context_id); | |
| 27 ASSERT_TRUE(tracker.GetContextIdForFrame("f", &context_id).IsOk()); | |
| 28 ASSERT_EQ(100, context_id); | |
| 29 | |
| 30 tracker.OnEvent("DOM.documentUpdated", params); | |
| 31 ASSERT_TRUE(tracker.GetContextIdForFrame("f", &context_id).IsError()); | |
| 32 } | |
| 33 | |
| 34 TEST(FrameTracker, GetFrameForContextId) { | |
| 35 StubDevToolsClient client; | |
| 36 FrameTracker tracker(&client); | |
| 37 std::string frame_id = "NONE"; | |
| 38 ASSERT_TRUE(tracker.GetFrameForContextId(0, &frame_id).IsError()); | |
| 39 ASSERT_EQ("NONE", frame_id); | |
| 40 | |
| 41 const char context[] = "{\"id\":100,\"frameId\":\"f\"}"; | |
| 42 base::DictionaryValue params; | |
| 43 params.Set("context", base::JSONReader::Read(context)); | |
| 44 tracker.OnEvent("Runtime.executionContextCreated", params); | |
| 45 ASSERT_TRUE(tracker.GetFrameForContextId(0, &frame_id).IsError()); | |
| 46 ASSERT_EQ("NONE", frame_id); | |
| 47 ASSERT_TRUE(tracker.GetFrameForContextId(100, &frame_id).IsOk()); | |
| 48 ASSERT_EQ("f", frame_id); | |
| 49 | |
| 50 tracker.OnEvent("DOM.documentUpdated", params); | |
| 51 ASSERT_TRUE(tracker.GetFrameForContextId(100, &frame_id).IsError()); | |
| 52 } | |
| OLD | NEW |