Title: [219721] trunk/Source/WebDriver
- Revision
- 219721
- Author
- [email protected]
- Date
- 2017-07-21 02:43:13 -0700 (Fri, 21 Jul 2017)
Log Message
WebDriver: correctly handle main frame handles
https://bugs.webkit.org/show_bug.cgi?id=174668
Reviewed by Brian Burg.
When I switched to use std::optional instead of empty strings for the browsing contexts in WebDriver, I forgot
that automation uses empty string for frames to refer to the main frame. We should handle that case, because we
are currently considering empty strings as valid browsing context. It's not a big deal because Automation
converts back the empty string received to the main frame, though. We should also ensure we close the current
browsing context when switching to a new top level browsing context. This patch adds to helper private methods
to switch browsing contexts that deal with the special cases.
* Session.cpp:
(WebDriver::Session::close):
(WebDriver::Session::switchToTopLevelBrowsingContext):
(WebDriver::Session::switchToBrowsingContext):
(WebDriver::Session::createTopLevelBrowsingContext):
(WebDriver::Session::go):
(WebDriver::Session::back):
(WebDriver::Session::forward):
(WebDriver::Session::refresh):
(WebDriver::Session::switchToWindow):
(WebDriver::Session::switchToFrame):
(WebDriver::Session::switchToParentFrame):
* Session.h:
Modified Paths
Diff
Modified: trunk/Source/WebDriver/ChangeLog (219720 => 219721)
--- trunk/Source/WebDriver/ChangeLog 2017-07-21 08:22:20 UTC (rev 219720)
+++ trunk/Source/WebDriver/ChangeLog 2017-07-21 09:43:13 UTC (rev 219721)
@@ -1,3 +1,31 @@
+2017-07-21 Carlos Garcia Campos <[email protected]>
+
+ WebDriver: correctly handle main frame handles
+ https://bugs.webkit.org/show_bug.cgi?id=174668
+
+ Reviewed by Brian Burg.
+
+ When I switched to use std::optional instead of empty strings for the browsing contexts in WebDriver, I forgot
+ that automation uses empty string for frames to refer to the main frame. We should handle that case, because we
+ are currently considering empty strings as valid browsing context. It's not a big deal because Automation
+ converts back the empty string received to the main frame, though. We should also ensure we close the current
+ browsing context when switching to a new top level browsing context. This patch adds to helper private methods
+ to switch browsing contexts that deal with the special cases.
+
+ * Session.cpp:
+ (WebDriver::Session::close):
+ (WebDriver::Session::switchToTopLevelBrowsingContext):
+ (WebDriver::Session::switchToBrowsingContext):
+ (WebDriver::Session::createTopLevelBrowsingContext):
+ (WebDriver::Session::go):
+ (WebDriver::Session::back):
+ (WebDriver::Session::forward):
+ (WebDriver::Session::refresh):
+ (WebDriver::Session::switchToWindow):
+ (WebDriver::Session::switchToFrame):
+ (WebDriver::Session::switchToParentFrame):
+ * Session.h:
+
2017-07-18 Carlos Garcia Campos <[email protected]>
WebDriver: handle invalid selector errors
Modified: trunk/Source/WebDriver/Session.cpp (219720 => 219721)
--- trunk/Source/WebDriver/Session.cpp 2017-07-21 08:22:20 UTC (rev 219720)
+++ trunk/Source/WebDriver/Session.cpp 2017-07-21 09:43:13 UTC (rev 219721)
@@ -71,7 +71,7 @@
completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
return;
}
- m_toplevelBrowsingContext = std::nullopt;
+ switchToTopLevelBrowsingContext(std::nullopt);
completionHandler(CommandResult::success());
});
}
@@ -87,6 +87,21 @@
completionHandler(CommandResult::success());
}
+void Session::switchToTopLevelBrowsingContext(std::optional<String> toplevelBrowsingContext)
+{
+ m_toplevelBrowsingContext = toplevelBrowsingContext;
+ m_browsingContext = std::nullopt;
+}
+
+void Session::switchToBrowsingContext(std::optional<String> browsingContext)
+{
+ // Automation sends empty strings for main frame.
+ if (!browsingContext || browsingContext.value().isEmpty())
+ m_browsingContext = std::nullopt;
+ else
+ m_browsingContext = browsingContext;
+}
+
void Session::createTopLevelBrowsingContext(Function<void (CommandResult&&)>&& completionHandler)
{
ASSERT(!m_toplevelBrowsingContext.value());
@@ -101,7 +116,7 @@
completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
return;
}
- m_toplevelBrowsingContext = handle;
+ switchToTopLevelBrowsingContext(handle);
completionHandler(CommandResult::success());
});
});
@@ -122,7 +137,7 @@
completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
return;
}
- m_browsingContext = std::nullopt;
+ switchToBrowsingContext(std::nullopt);
completionHandler(CommandResult::success());
});
}
@@ -169,7 +184,7 @@
completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
return;
}
- m_browsingContext = std::nullopt;
+ switchToBrowsingContext(std::nullopt);
completionHandler(CommandResult::success());
});
}
@@ -188,7 +203,7 @@
completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
return;
}
- m_browsingContext = std::nullopt;
+ switchToBrowsingContext(std::nullopt);
completionHandler(CommandResult::success());
});
}
@@ -207,7 +222,7 @@
completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
return;
}
- m_browsingContext = std::nullopt;
+ switchToBrowsingContext(std::nullopt);
completionHandler(CommandResult::success());
});
}
@@ -289,7 +304,7 @@
completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
return;
}
- m_toplevelBrowsingContext = windowHandle;
+ switchToTopLevelBrowsingContext(windowHandle);
completionHandler(CommandResult::success());
});
}
@@ -340,7 +355,7 @@
}
if (frameID->isNull()) {
- m_browsingContext = std::nullopt;
+ switchToBrowsingContext(std::nullopt);
completionHandler(CommandResult::success());
return;
}
@@ -381,7 +396,7 @@
completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
return;
}
- m_browsingContext = frameHandle;
+ switchToBrowsingContext(frameHandle);
completionHandler(CommandResult::success());
});
}
@@ -411,7 +426,7 @@
completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
return;
}
- m_browsingContext = frameHandle;
+ switchToBrowsingContext(frameHandle);
completionHandler(CommandResult::success());
});
}
Modified: trunk/Source/WebDriver/Session.h (219720 => 219721)
--- trunk/Source/WebDriver/Session.h 2017-07-21 08:22:20 UTC (rev 219720)
+++ trunk/Source/WebDriver/Session.h 2017-07-21 09:43:13 UTC (rev 219721)
@@ -104,6 +104,9 @@
private:
Session(std::unique_ptr<SessionHost>&&);
+ void switchToTopLevelBrowsingContext(std::optional<String>);
+ void switchToBrowsingContext(std::optional<String>);
+
RefPtr<Inspector::InspectorObject> createElement(RefPtr<Inspector::InspectorValue>&&);
RefPtr<Inspector::InspectorObject> createElement(const String& elementID);
RefPtr<Inspector::InspectorObject> extractElement(Inspector::InspectorValue&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes