Skip to content

Commit

Permalink
JasonLeyba: Changing how the atoms header files are generated:
Browse files Browse the repository at this point in the history
- Use multi-line strings instead of arrays to avoid unnecessary concatenations each time an atom is used.
- Move the atoms into their own namespace: webdriver::atoms.
- Add an option to use char instead of wchar_t.

r11406
  • Loading branch information
jleyba committed Feb 14, 2011
1 parent 5137bbe commit 986a823
Show file tree
Hide file tree
Showing 18 changed files with 4,107 additions and 4,297 deletions.
8 changes: 1 addition & 7 deletions cpp/IEDriver/ClearElementCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ class ClearElementCommandHandler : public WebDriverCommandHandler {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; CLEAR[j]; j++) {
script += CLEAR[j];
}

// Now for the magic and to close things
script += atoms::CLEAR;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down
16 changes: 2 additions & 14 deletions cpp/IEDriver/ElementFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ int ElementFinder::FindElement(BrowserManager *manager, ElementWrapper *parent_w
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; FIND_ELEMENT[j]; j++) {
script += FIND_ELEMENT[j];
}

// Now for the magic and to close things
script += atoms::FIND_ELEMENT;
script += L")})();";

ScriptWrapper *script_wrapper = new ScriptWrapper(doc, script, 2);
Expand Down Expand Up @@ -75,13 +69,7 @@ int ElementFinder::FindElements(BrowserManager *manager, ElementWrapper *parent_
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; FIND_ELEMENTS[j]; j++) {
script += FIND_ELEMENTS[j];
}

// Now for the magic and to close things
script += atoms::FIND_ELEMENTS;
script += L")})();";

ScriptWrapper *script_wrapper = new ScriptWrapper(doc, script, 2);
Expand Down
32 changes: 4 additions & 28 deletions cpp/IEDriver/ElementWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ int ElementWrapper::IsDisplayed(bool *result) {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; IS_DISPLAYED[j]; j++) {
script += IS_DISPLAYED[j];
}

// Now for the magic and to close things
script += atoms::IS_DISPLAYED;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand All @@ -73,13 +67,7 @@ bool ElementWrapper::IsEnabled() {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; IS_ENABLED[j]; j++) {
script += IS_ENABLED[j];
}

// Now for the magic and to close things
script += atoms::IS_ENABLED;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down Expand Up @@ -161,13 +149,7 @@ int ElementWrapper::GetAttributeValue(std::wstring attribute_name, VARIANT *attr
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; GET_ATTRIBUTE[j]; j++) {
script += GET_ATTRIBUTE[j];
}

// Now for the magic and to close things
script += atoms::GET_ATTRIBUTE;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down Expand Up @@ -246,13 +228,7 @@ bool ElementWrapper::IsSelected() {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; IS_SELECTED[j]; j++) {
script += IS_SELECTED[j];
}

// Now for the magic and to close things
script += atoms::IS_SELECTED;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down
12 changes: 4 additions & 8 deletions cpp/IEDriver/FindByCssSelectorElementFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class FindByCssSelectorElementFinder : public ElementFinder {
}

std::wstring script(L"(function() { return function(){");
for (int i = 0; SIZZLE[i]; i++) {
script += SIZZLE[i];
script += L"\n";
}
script += atoms::SIZZLE;
script += L"\n";
script += L"var root = arguments[1] ? arguments[1] : document.documentElement;";
script += L"if (root['querySelector']) { return root.querySelector(arguments[0]); } ";
script += L"var results = []; Sizzle(arguments[0], root, results);";
Expand Down Expand Up @@ -68,10 +66,8 @@ class FindByCssSelectorElementFinder : public ElementFinder {
}

std::wstring script(L"(function() { return function(){");
for (int i = 0; SIZZLE[i]; i++) {
script += SIZZLE[i];
script += L"\n";
}
script += atoms::SIZZLE;
script += L"\n";
script += L"var root = arguments[1] ? arguments[1] : document.documentElement;";
script += L"if (root['querySelectorAll']) { return root.querySelectorAll(arguments[0]); } ";
script += L"var results = []; Sizzle(arguments[0], root, results);";
Expand Down
8 changes: 1 addition & 7 deletions cpp/IEDriver/GetElementLocationCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ class GetElementLocationCommandHandler : public WebDriverCommandHandler {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; GET_LOCATION[j]; j++) {
script += GET_LOCATION[j];
}

// Now for the magic and to close things
script += atoms::GET_LOCATION;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down
8 changes: 1 addition & 7 deletions cpp/IEDriver/GetElementSizeCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ class GetElementSizeCommandHandler : public WebDriverCommandHandler {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; GET_SIZE[j]; j++) {
script += GET_SIZE[j];
}

// Now for the magic and to close things
script += atoms::GET_SIZE;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down
8 changes: 1 addition & 7 deletions cpp/IEDriver/GetElementTextCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ class GetElementTextCommandHandler : public WebDriverCommandHandler {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; GET_TEXT[j]; j++) {
script += GET_TEXT[j];
}

// Now for the magic and to close things
script += atoms::GET_TEXT;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down
8 changes: 1 addition & 7 deletions cpp/IEDriver/IsElementSelectedCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ class IsElementSelectedCommandHandler : public WebDriverCommandHandler {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; IS_SELECTED[j]; j++) {
script += IS_SELECTED[j];
}

// Now for the magic and to close things
script += atoms::IS_SELECTED;
script += L")})();";

ElementWrapper *element_wrapper;
Expand Down
8 changes: 1 addition & 7 deletions cpp/IEDriver/SubmitElementCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ class SubmitElementCommandHandler : public WebDriverCommandHandler {
// function: "function() {...}"; Wrap it in another function so we can
// invoke it with our arguments without polluting the current namespace.
std::wstring script(L"(function() { return (");

// Read in all the scripts
for (int j = 0; SUBMIT[j]; j++) {
script += SUBMIT[j];
}

// Now for the magic and to close things
script += atoms::SUBMIT;
script += L")})();";

CComPtr<IHTMLDocument2> doc;
Expand Down
Loading

0 comments on commit 986a823

Please sign in to comment.